From patchwork Mon Feb 10 13:16:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 1235817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48GRHz6yTLzB3x6 for ; Tue, 11 Feb 2020 00:16:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48GRHy366HzDqNw for ; Tue, 11 Feb 2020 00:16:30 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=kaod.org (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=groug@kaod.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48GRHp2GWQzDqNg for ; Tue, 11 Feb 2020 00:16:19 +1100 (AEDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01ADFFVm041236 for ; Mon, 10 Feb 2020 08:16:16 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y1umrmv35-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 10 Feb 2020 08:16:15 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Feb 2020 13:16:13 -0000 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 10 Feb 2020 13:16:11 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01ADGA5843516182 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Feb 2020 13:16:10 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 470B742041; Mon, 10 Feb 2020 13:16:10 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E67442045; Mon, 10 Feb 2020 13:16:10 +0000 (GMT) Received: from bahia.lan (unknown [9.145.71.236]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 10 Feb 2020 13:16:10 +0000 (GMT) From: Greg Kurz To: Alexey Kardashevskiy Date: Mon, 10 Feb 2020 14:16:09 +0100 User-Agent: StGit/unknown-version MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20021013-4275-0000-0000-0000039FC401 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20021013-4276-0000-0000-000038B3F7FB Message-Id: <158134056935.2963469.11427374783836284547.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-02-10_04:2020-02-10, 2020-02-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 spamscore=0 priorityscore=1501 clxscore=1034 impostorscore=0 malwarescore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002100104 Subject: [SLOF] [PATCH v2] fdt: Delete nodes of devices removed between boot and CAS X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: slof@lists.ozlabs.org Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" We recently fixed node creation at CAS in order to support early hotplug of devices between boot and CAS. Let's handle node removal now to support early hot *un*plug of devices. This is achieved by associating a generation number to each FDT received from QEMU and tagging all nodes with this number in a "slof,from-fdt" property. The generation number is kept in the fdt-generation# variable. It starts at 0 for the initial boot time FDT, and it is incremented at each subsequent CAS. All boot time nodes hence get "slof,from-fdt" == 0, all nodes present at CAS get "slof,from-fdt" == 1 and so on in case the guest calls CAS again. If a device gets hot unplugged before quiesce, we hence can detect it doesn't have the right generation number and thus delete the node from the DT. Note that this only affects nodes coming from the FDT. Nodes created by SLOF don't have the "slof,from-fdt" property, and therefore cannot be candidates to deletion. Signed-off-by: Greg Kurz --- v2: - global rewrite using a generation number which gets copied to a "slof,from-fdt" property - delete aliases in a separate loop --- board-qemu/slof/fdt.fs | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/board-qemu/slof/fdt.fs b/board-qemu/slof/fdt.fs index 66f8fe74d9dd..6a694c17517a 100644 --- a/board-qemu/slof/fdt.fs +++ b/board-qemu/slof/fdt.fs @@ -13,6 +13,11 @@ 1 VALUE fdt-debug TRUE VALUE fdt-cas-fix? 0 VALUE fdt-cas-pass +0 VALUE fdt-generation# + +: fdt-update-from-fdt ( -- ) + fdt-generation# encode-int s" slof,from-fdt" property +; \ Bail out if no fdt fdt-start 0 = IF -1 throw THEN @@ -198,6 +203,8 @@ fdt-check-header decode-int dup fdt-create-dec fdt-create-enc 2drop THEN + fdt-update-from-fdt + finish-device ; @@ -514,6 +521,9 @@ r> drop swap ( newnode? a1 ) fdt-debug IF ." Current now: " pwd get-node ." = " . cr THEN + fdt-cas-pass 0= IF + fdt-update-from-fdt + THEN BEGIN fdt-next-tag dup OF_DT_END_NODE <> WHILE @@ -584,8 +594,70 @@ r> drop THEN ; +: alias-dev-path ( xt -- dev-path len ) + link> execute decode-string 2swap 2drop +; + +: alias-name ( xt -- alias-name len ) + link> >name name>string +; + +: fdt-cas-alias-obsolete? ( xt -- true|false ) + alias-dev-path find-node 0= +; + +: (fdt-cas-delete-obsolete-aliases) ( xt -- ) + dup IF + dup @ + recurse + dup alias-name s" name" str= IF ELSE + dup fdt-cas-alias-obsolete? IF + fdt-debug IF ." Deleting obsolete alias: " dup alias-name type ." -> " dup alias-dev-path type cr THEN + dup alias-name + delete-property + THEN + THEN + THEN + drop +; + +: fdt-cas-delete-obsolete-aliases ( -- ) + s" /aliases" find-device + get-node node>properties @ cell+ @ (fdt-cas-delete-obsolete-aliases) + device-end +; + +: fdt-cas-node-obsolete? ( node -- true|false) + s" slof,from-fdt" rot get-package-property IF + \ Not a QEMU originated node + false + ELSE + decode-int nip nip fdt-generation# < + THEN +; + +: (fdt-cas-search-obsolete-nodes) ( start node -- ) + dup IF + dup child 2 pick swap recurse + dup peer 2 pick swap recurse + + dup fdt-cas-node-obsolete? IF + fdt-debug IF dup ." Deleting obsolete node: " dup .node ." = " . cr THEN + dup delete-node + THEN + THEN + 2drop +; + +: fdt-cas-delete-obsolete-nodes ( start -- ) + s" /" find-device get-node (fdt-cas-search-obsolete-nodes) + fdt-cas-delete-obsolete-aliases +; + : fdt-fix-cas-node ( start -- ) + fdt-generation# 1+ to fdt-generation# 0 to fdt-cas-pass dup (fdt-fix-cas-node) drop \ Add phandles + dup fdt-cas-delete-obsolete-nodes \ Delete removed devices 1 to fdt-cas-pass dup (fdt-fix-cas-node) drop \ Patch+add other properties 2 to fdt-cas-pass dup (fdt-fix-cas-node) drop \ Delete phandles from pass 0 drop