From patchwork Mon Jul 31 21:02:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708424 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2523144wru; Mon, 31 Jul 2023 14:04:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlHE52CObXfjiF7dTHbPoPl9a0Cq+pw9xk2UmQrOK67JRqw1pEVHO+9X24/OQce93EUxjKna X-Received: by 2002:a05:6358:9390:b0:134:eed0:3bc5 with SMTP id h16-20020a056358939000b00134eed03bc5mr1034229rwb.9.1690837497573; Mon, 31 Jul 2023 14:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837497; cv=none; d=google.com; s=arc-20160816; b=n5hqM+Jku9/0VEm5fbM2oOQRsCjkw5wAQ13e0wLAK4Blwiq3IKSH9GfcKodWI55Jxi c7j9v12OMqPEAQOs6vmeV3bE4nxMW7m0uZw+Xv4ZxV6KbuIQqFAY/CdAo/537BmRXZy9 3g0BNOoSDLyZdE6uzRxypE/cC8DeLSr/KmMdgJuXh87USdSjXgMXDHN4Y46EY9Gb/SVV ibnHv5HCK+Irwck9hkujDopeAQyMjHYl9I/vQA8quEjR++vXmzeYjhmjFrxIexQDj9NV CcfqXwFKwlg6ndkYmdzD5JJSdmd7a4sR4M4dWYRYB2HnpYk5ekfHg44jdBBwpYKGdH8j n/iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Wm4GRXTtNsgafsC2QchrPp0CcNNwD+XuJ7FjQ2Qh7j0=; fh=20zcLA4cqjW/3I5wZ98zlxuHItai5Ka4phUhNNfJNfQ=; b=AXUHyVBJ6pt7bpWnk4xFxYDzZZo71J0Vd/fW1LtdRnQQ99sCtMw4rbYaZzeUna+B1Q a/eyQwZWD8CjoNVUTOhE8FUWLp0hir9vLu8N6OiRSLUgcOBwEQf+UKNi0OTevo99rLQ4 MXccWb4VbkO4m2l6tYU9i/0na8owtpnda7nMn+K7/yB7b4LCqXwIG33W5drJjCiBUbZG CGbW3/+xy5hf+2yJt3ZZpjyvk7m15z/bDMhca7I6GdOqb7XkSq7ONLjGfSRbrxsFQM5e TSnb79NoDhwA/8kYr08WzR8JovKuotgsid0OaNFuI1RZXTAvbBDOoSk4mrvvBdipP0/I Xtfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vZFSz+3e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y4-20020a0cd984000000b0062fe83687e8si5113345qvj.268.2023.07.31.14.04.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:04:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vZFSz+3e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa1y-0000oS-Br; Mon, 31 Jul 2023 17:02:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa1w-0000nQ-Jc for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:16 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa1v-0006M6-0k for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:16 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1bc02bd4eafso17987665ad.1 for ; Mon, 31 Jul 2023 14:02:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837334; x=1691442134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wm4GRXTtNsgafsC2QchrPp0CcNNwD+XuJ7FjQ2Qh7j0=; b=vZFSz+3e0gk1wqoGnSzwi6OCMMItlZBc89kuoAnaOHzlUpKE0TBk55jpqAwnDFyzcV 6JDDoQZv3EMfvr21/QL2GB7gWFkioFNVb1GLQwNMvi0VhlsqIOM8XFjTZv27Y+kynx/p oqfmqj7jp54ei6gD/PKUNP5pFi6JeKSVuEV/UREscdS/JWUhw/tNxHDdFEr6CLz1HQM6 dnCmaB/wV6W6xrUXlApZfmlvX82OyFED+chGjizF2jeS6+H35OoASr1I9IjuV6qjvPIW CdlJP/8FxbmdQEtVjkH2Wd2VGTOIH4kukPQy5lOrywueij3mhCabpL3ONhpkggvZI0Xa Qc/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837334; x=1691442134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wm4GRXTtNsgafsC2QchrPp0CcNNwD+XuJ7FjQ2Qh7j0=; b=Kc2eqnRNevJyKSGNuCPRa+clxMH2DcmqLuW6lT/2oGg+FWzHnfLInAdbislgVhk6Vx 9HGHrN8jTFj7S+kqE8nxvnRlNz9MyQrioDqUixwX23eQAJaK7n70YK4aIs+Mc7GfBF4o de21LaWMFPaF63ErmmMWB6ZfwgANXSR/x68Mn6YJpQqnMuYGmxMGWTxi4kU954vnuHo6 ZQCLSUSUNfHHjnEyax16iSnK6crskGVAXn/IF84dHM7TbUS0nAaQ+JPilQTBsC7xvvgX fWCIoN7wlegqRP+u93LyVlxyCfILTKrbduQ9TaMIGt4as0Hq0Rt/LaYREX2s91a8asf+ LO9Q== X-Gm-Message-State: ABy/qLZwlOeydQnnY25Tk3zdlOZy5Ox2uYq7pr0/0GK4d4ZRA3ks1WUE upPHVGxk4L6AejSiHBL7G8dKbfpYc/ziGiwieYk= X-Received: by 2002:a17:902:988e:b0:1b2:1a79:147d with SMTP id s14-20020a170902988e00b001b21a79147dmr11047962plp.2.1690837333797; Mon, 31 Jul 2023 14:02:13 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Maydell Subject: [PULL 01/10] util/interval-tree: Use qatomic_read for left/right while searching Date: Mon, 31 Jul 2023 14:02:02 -0700 Message-Id: <20230731210211.137353-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Fixes a race condition (generally without optimization) in which the subtree is re-read after the protecting if condition. Cc: qemu-stable@nongnu.org Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- util/interval-tree.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/util/interval-tree.c b/util/interval-tree.c index 4c0baf108f..5a0ad21b2d 100644 --- a/util/interval-tree.c +++ b/util/interval-tree.c @@ -745,8 +745,9 @@ static IntervalTreeNode *interval_tree_subtree_search(IntervalTreeNode *node, * Loop invariant: start <= node->subtree_last * (Cond2 is satisfied by one of the subtree nodes) */ - if (node->rb.rb_left) { - IntervalTreeNode *left = rb_to_itree(node->rb.rb_left); + RBNode *tmp = qatomic_read(&node->rb.rb_left); + if (tmp) { + IntervalTreeNode *left = rb_to_itree(tmp); if (start <= left->subtree_last) { /* @@ -765,8 +766,9 @@ static IntervalTreeNode *interval_tree_subtree_search(IntervalTreeNode *node, if (start <= node->last) { /* Cond2 */ return node; /* node is leftmost match */ } - if (node->rb.rb_right) { - node = rb_to_itree(node->rb.rb_right); + tmp = qatomic_read(&node->rb.rb_right); + if (tmp) { + node = rb_to_itree(tmp); if (start <= node->subtree_last) { continue; } @@ -814,8 +816,9 @@ IntervalTreeNode *interval_tree_iter_first(IntervalTreeRoot *root, IntervalTreeNode *interval_tree_iter_next(IntervalTreeNode *node, uint64_t start, uint64_t last) { - RBNode *rb = node->rb.rb_right, *prev; + RBNode *rb, *prev; + rb = qatomic_read(&node->rb.rb_right); while (true) { /* * Loop invariants: @@ -840,7 +843,7 @@ IntervalTreeNode *interval_tree_iter_next(IntervalTreeNode *node, } prev = &node->rb; node = rb_to_itree(rb); - rb = node->rb.rb_right; + rb = qatomic_read(&node->rb.rb_right); } while (prev == rb); /* Check if the node intersects [start;last] */ From patchwork Mon Jul 31 21:02:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708417 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2522453wru; Mon, 31 Jul 2023 14:03:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlEv6Y06m3aURvHPg895FT5L3fQT1bXQJ1f98k2etbxjtDDKlriP39/WAk3bywAlRNjOFIDn X-Received: by 2002:a05:620a:44d0:b0:76a:ece7:2071 with SMTP id y16-20020a05620a44d000b0076aece72071mr13695373qkp.41.1690837410844; Mon, 31 Jul 2023 14:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837410; cv=none; d=google.com; s=arc-20160816; b=nidMx2MSdzi6TVppM6m+2rx942FxrKgg8NLjT3yQo9a53IhpSVevJRZlQxUllXECBk Ggj7Wg8jD4wsqU+fKmLQllNF6JZbY6Jy0KDpU6hhOOsmsNYQVFSBoszn7nHe7AdEmeZo 7b9PYDQTkKWdoyvPsLZhPNAkG8szmih2JHGRA+GopNtyDsA1WN/ZvQnLGbv86a2UNlts l1SbkvoE7m3a/oSHPBrfIBARTNkHj/vVAbp+GAvxdN6e/oF6ijk4Am/YqpxLiSAdZbth 51Z2pRd59dJJxMBNxXvcTtQG6csDWOIjzNsZuZfg6HWapmuyxNF1kHiZvlD5xI2ukH++ io4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MA43mJPR4S1w+5iUDGlCigiGv8RYffvPZ7jW3KkkkqY=; fh=20zcLA4cqjW/3I5wZ98zlxuHItai5Ka4phUhNNfJNfQ=; b=bLth90ue1fdRfnHHpSCZlP4dIT3Q6iFYKyBvr1Pw2h8naRlRYo7SquKUoeVXMZJvRX 0LjaWbQnFnmXFvjy+B9fRB68RJqOCyyEWhgv9exH2/FX/XeeHon1GPswpFFTuTO9JVOu ZruOXgavQkxFP+4Rk9S06G4AbWQ6oLh1GipJNSlxo/YObN8VPpXaSyKvqZr4AeCZNQGe kIkY7lLH2l7SG7GcutC/2m3yQO4j9a6AELo9ixfbuRLhkxKZXMkucddqcSGpLQzLeuJW +a28p7z+cSAsuXxaH57ajfq1FVvSHwbzmRl6SFEo2mFqm5YFkVoEppwHYhPj1I5cWrOf QXzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cnGCnJqq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m17-20020a05620a291100b00767b7436df3si6547794qkp.319.2023.07.31.14.03.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:03:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cnGCnJqq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa1z-0000p4-Nq; Mon, 31 Jul 2023 17:02:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa1x-0000ns-ON for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:17 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa1w-0006Me-2L for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:17 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686b91c2744so3549453b3a.0 for ; Mon, 31 Jul 2023 14:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837334; x=1691442134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MA43mJPR4S1w+5iUDGlCigiGv8RYffvPZ7jW3KkkkqY=; b=cnGCnJqqN4OfwiB0PvTjzUO6GXxsNjPqBlL9J8Iy38HrST4Uxez8/EljBqcWQEqyTX x6Ci/EReAK8TdaZxilC77JTpudNJ2Qos13ZQkcUsMxDV+6bt6RDcp0tuHLclSXLTzKFG PUWed66a8f0pWHkGD3ja4z4Qwb9hKDUQOLJglU0EteoR9oHGowLw/vRiVvNoioTXHHWZ OxQ1Ul+GudS8fZta9Z8HrSqUWGy+f8GEMfiPGSBZ3GIV/16mrtAX+vRP9DSVvro0gBMi 7Ib8WHx1b+IAid8+mT6V11E6IzWKq/+Nm3Bu/VSwCMfIjbHvgA6yGx2K00qAK3HtzlDb OfUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837334; x=1691442134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MA43mJPR4S1w+5iUDGlCigiGv8RYffvPZ7jW3KkkkqY=; b=hfJKVJvYdGAG0qUC9CMgAhbIC5UkJVTjFpRbUXFmFDX+GHt/qSDuHwnzT3ZiKoddTp 1U7k+ElGsY1HWwPZ6s02/Z0p/QLqASP8nbVP3Hby6akhk/Yz8lcirrqiELBf2L4q4Unv uPj45+WkztwjmXU8OAkp6MpNjlP1FGbRf/Uq5oBmHIr2K4/5tW6bSKfAeqkZJMy1uJOG fI4VnsiQZN1jFT//X0SRumbOELOhuPylHXhI1t020s0j2f8Wrvy10D/l71oNssOQF7jK da6MfKN4o/TB9eX3cHiCddwxAc/802LNb0kpfVyTdXErZalqurpWr+QKK7eHasa6YPeW gNSQ== X-Gm-Message-State: ABy/qLaC2Hqv0hMfrRDDVWBjFJnPc2Wwm22lHslgwW5CbX5pmwMs5pTJ FtI46rtaG1DNV59vj/mV0uLV7jnxzJtIWMrfw+4= X-Received: by 2002:a17:90a:de90:b0:267:f5d1:1dd3 with SMTP id n16-20020a17090ade9000b00267f5d11dd3mr9408459pjv.11.1690837334647; Mon, 31 Jul 2023 14:02:14 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Maydell Subject: [PULL 02/10] util/interval-tree: Use qatomic_set_mb in rb_link_node Date: Mon, 31 Jul 2023 14:02:03 -0700 Message-Id: <20230731210211.137353-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Ensure that the stores to rb_left and rb_right are complete before inserting the new node into the tree. Otherwise a concurrent reader could see garbage in the new leaf. Cc: qemu-stable@nongnu.org Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- util/interval-tree.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/interval-tree.c b/util/interval-tree.c index 5a0ad21b2d..759562db7d 100644 --- a/util/interval-tree.c +++ b/util/interval-tree.c @@ -128,7 +128,11 @@ static inline void rb_link_node(RBNode *node, RBNode *parent, RBNode **rb_link) node->rb_parent_color = (uintptr_t)parent; node->rb_left = node->rb_right = NULL; - qatomic_set(rb_link, node); + /* + * Ensure that node is initialized before insertion, + * as viewed by a concurrent search. + */ + qatomic_set_mb(rb_link, node); } static RBNode *rb_next(RBNode *node) From patchwork Mon Jul 31 21:02:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708420 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2522820wru; Mon, 31 Jul 2023 14:04:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlH7+1egiMtX8BbBlDM3rAtSN5ETWdj42tYI7CR8xLP5P6+8m20QyCM9Uk1XGyx/3qwN0jFy X-Received: by 2002:a05:6214:1910:b0:625:bb19:278c with SMTP id er16-20020a056214191000b00625bb19278cmr8981742qvb.2.1690837458032; Mon, 31 Jul 2023 14:04:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837458; cv=none; d=google.com; s=arc-20160816; b=tKQTcsNIDT5VqL2Z8BIR5zkrZZFlXHo8OPnScO9u6eHj0uuL9ThEdYIksYlUTwFuoT O009wAxGRTZpvlRRnKdueLZljP9LVEVfwwUF4VMJQKCba4uvyRKtuyQWFumHLYmOXWh9 rPjUwOR5v1X0WNavsIAJSXVuNMWILR5GIdfFdK/ZicjTf7pS7wXLlePiljeDBWq8ThCB AYZuI/GW27KEJuCnHEoxe3naD+/ekMjjuVaLLfMGXah7eoy/bx2zbW9H433d6NW6B/ke +cdY3QHZGV//gf1lSBPvI3bxy1wZnXwK9TibWptluxM1SzcRFzMOnwoM6BUIFBPCaPy9 8XtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rB9T/dW/PWoV+QiJ6XYC1bP+RmxJz6XfaOi54UnlvMA=; fh=iKWO5kImkBaf5P/04M2d2o+fJodoyCg8YLKe8/cbiwg=; b=H1+EkJnrI/yarhOiD4Tz6wqhNP09bICtRSGjRCZOFxDnkzAEbVoV/gDws10PZT+PEh Vn3/lwY0zto7qUxvfhRdGQcTjQ6COnwP6Eo20t7GUdYOpsivQcN7/r8u78KFfypKWeH/ z2WcrSgZ/iRW6mp1a2gE0E4iUVhBXVoUz5h9RsmUhpjo7fk0H1O0dDspI7k9eERGI6M6 xLJ2AV4zVAtijOay+2ZMyYy4ZHr+GZxNPNuLS0TpNFDSm0hEcaaAjnLfigSpto42mtNw AY9uqYmfYS49TPr3fnvld3+PiNhQLSWoySJt7IvCwCHXBWCMBGoxpp4+luyrumvsWoCN LNCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TB4xxgkq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f25-20020a0caa99000000b0063cf3fba03fsi6219545qvb.352.2023.07.31.14.04.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:04:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TB4xxgkq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa20-0000pu-H4; Mon, 31 Jul 2023 17:02:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa1z-0000ol-1L for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:19 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa1x-0006NK-B8 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:18 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1b9cdef8619so30895025ad.0 for ; Mon, 31 Jul 2023 14:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837336; x=1691442136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rB9T/dW/PWoV+QiJ6XYC1bP+RmxJz6XfaOi54UnlvMA=; b=TB4xxgkqXFVE2y3+OQQWBOMSvC6igAdqcbDaAFrF2+vTMJJFEHeDcdtOtzjBBmuLYZ 0ecyHNnbN0Vpf+M+uBO47D6dEUFPvfBXSK3I5fdcl6FPbKs706Eag2juT/7Bj+D83VBp VBwxnc0txp33IYuf0zyRuhGsuo/UKNFOGP+9goSIHks598d8ljzAgdhVPkJZfx2Src4T XvWH2OsaxfUOIB3q1Q1Vc4KXxPZ/muBjmOgCAYSHpKcR+pHE6pEi/6Sg0Y27oaB4olw3 YVPHv0v+s8SJiEOlDpPcKKL//jG6YBC2de0zPA+gnSQAfaLXYbb3TUVINp0X+aHhrBMz GTIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837336; x=1691442136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rB9T/dW/PWoV+QiJ6XYC1bP+RmxJz6XfaOi54UnlvMA=; b=MPwkxx0Nqgj+hHYqHEAbcS3T8VlAZ1BXkHH6FLYZf6YyVTvNzzJRYL+Vc+jI/9Nnd6 TL/w4DebOhFhjhCi+HKQQGo9DB49jrNQGqOjW+xeWBmDETv7oZZqkVU1tMt8BarIm06h iE3FnW79PjzkWqBZWdJExESclsO7UEqIRFdB1EoJ/tlXn0VGPwqw24XoLCNItiGVOEgB uhuHvQLY20hs0/TJjs17iuu99qkUASyPDOLhgaxaYePFnnFf3l2CZJ89NasWq0k1rQjy JoEkDfrRq3XTfnwKxeGLjKs8Q1OuFONPKc3tEEHZBjXNVRS7AtzaRMTYwOSl17042BdH x8aA== X-Gm-Message-State: ABy/qLY6LipHfBZgiktfK8+Xq0zJVHIdvIKXjl66uX1tFMH9y/dZhyy8 tnb8YaABd+PmkZVlHgTGa/yRiWrOVUUgb2h2uYw= X-Received: by 2002:a17:903:22c6:b0:1b8:41d4:89f with SMTP id y6-20020a17090322c600b001b841d4089fmr12322778plg.4.1690837335719; Mon, 31 Jul 2023 14:02:15 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 03/10] util/interval-tree: Introduce pc_parent Date: Mon, 31 Jul 2023 14:02:04 -0700 Message-Id: <20230731210211.137353-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- util/interval-tree.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/util/interval-tree.c b/util/interval-tree.c index 759562db7d..d86c0752db 100644 --- a/util/interval-tree.c +++ b/util/interval-tree.c @@ -68,9 +68,14 @@ typedef struct RBAugmentCallbacks { void (*rotate)(RBNode *old, RBNode *new); } RBAugmentCallbacks; +static inline RBNode *pc_parent(uintptr_t pc) +{ + return (RBNode *)(pc & ~1); +} + static inline RBNode *rb_parent(const RBNode *n) { - return (RBNode *)(n->rb_parent_color & ~1); + return pc_parent(n->rb_parent_color); } static inline RBNode *rb_red_parent(const RBNode *n) @@ -532,7 +537,7 @@ static void rb_erase_augmented(RBNode *node, RBRoot *root, * so as to bypass rb_erase_color() later on. */ pc = node->rb_parent_color; - parent = rb_parent(node); + parent = pc_parent(pc); rb_change_child(node, child, parent, root); if (child) { child->rb_parent_color = pc; @@ -544,7 +549,7 @@ static void rb_erase_augmented(RBNode *node, RBRoot *root, } else if (!child) { /* Still case 1, but this time the child is node->rb_left */ pc = node->rb_parent_color; - parent = rb_parent(node); + parent = pc_parent(pc); tmp->rb_parent_color = pc; rb_change_child(node, tmp, parent, root); rebalance = NULL; @@ -600,7 +605,7 @@ static void rb_erase_augmented(RBNode *node, RBRoot *root, rb_set_parent(tmp, successor); pc = node->rb_parent_color; - tmp = rb_parent(node); + tmp = pc_parent(pc); rb_change_child(node, successor, tmp, root); if (child2) { From patchwork Mon Jul 31 21:02:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708414 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2522333wru; Mon, 31 Jul 2023 14:03:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlHagKYgX8pybrD8YgKmZ7n4vMukFx3Z2RwR6gGzDKHQBQN7GrjXTtyDNOKTNpNmVcOkhxQr X-Received: by 2002:a0c:f4c7:0:b0:63d:651e:4131 with SMTP id o7-20020a0cf4c7000000b0063d651e4131mr3047390qvm.30.1690837394816; Mon, 31 Jul 2023 14:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837394; cv=none; d=google.com; s=arc-20160816; b=wMydOPRyaa9sEMIg6gwfv7dHxSWk4hy5MWWc5EmP/09fO/igKwlwdYoUqGCYJKgL+7 OxGuPyNWwbPNpYsY8vYrqSNbH2XYhsO1XmrpxI0yj2VWR5sLg50sS52DUJ2TBGWuE/JB XvZmP3WlQCiHKQJ+Y4nxKrJtzFE0cpDf3bvbQgbpyo1KEMCaURSPboWfrD8CzqTPIkQG Rl4U7NHi3gOyVg7SSL6Zmsb5NkdkwNWYt46mjwgQtUPXAR3dKU97SqUlantTIxFK9y58 f6AZ1sbfFyl2PhGjS9PgOdqD0fzg4I4heHLIHJvGXimbLEzXKJlBbCkSf/wefbe1jzSh pLSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mSaiqNFB6jjwG6Ld2HBVU8RlVJLDefjbnB1ExR7a8lc=; fh=iKWO5kImkBaf5P/04M2d2o+fJodoyCg8YLKe8/cbiwg=; b=Bum9PeoXV4Xwn4jV2/Uhbti2zY2njRKRE/zI79ylzI5RGsHWFJ7kByL/SeRa6Rpibk zMArE80FmEBbnjbMIwfN6hCYWh1hxefQilJHtRp1ZysRjls2uSizgDO09HzxCmA+/JHe flyJzSvYMTfvwdvMAqcC3eA55sMwld90tc/f6leBEwZDP3Mz7lud2SbjoMrAQOWGDrfH g5QUqJqyg1aHeCudi+qDV9vp1Fb2QL4/CnhblyTCYVTHdMAjUerCkHv0LsAzHxO5Znya tYlxBpr5smDIbHN1fIPuBQEEyAwILPlp0dunLkLR0pRzPQagPJ2ktcUOOEQh1aqlR8x8 kQjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="nLZbXqv/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id rg3-20020a05620a8ec300b00767e5eca0casi6026120qkn.197.2023.07.31.14.03.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:03:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="nLZbXqv/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa21-0000qm-OQ; Mon, 31 Jul 2023 17:02:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa1z-0000pJ-TZ for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:20 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa1y-0006O5-14 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:19 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bbc64f9a91so41992255ad.0 for ; Mon, 31 Jul 2023 14:02:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837336; x=1691442136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mSaiqNFB6jjwG6Ld2HBVU8RlVJLDefjbnB1ExR7a8lc=; b=nLZbXqv/52iHwGyg2zsQMW9ocy2hzVUi8NLCeymLuPl47DSDWum+fzp9gnQ1zSk9F3 HS3BLciiiz6oEWa7+HN3xvG9FtV8KrIhc1OdHlybbqaPZbLWGkfU/OLChPC2MS/0K9nD zkPqLFujZwZVBCjtnYdahBaG1ebNDgChFXjh9wuN7FCXx7RanqbfK0ca7hN48yZQ+c5F oVMUnsneR3FY9mVk87R8zesS9uYmz8fT6Ajn4QstWldrcfp86jX9wqdGkmtPbCGmx8mq rnVToLr5V3mw3FmInSr1tskFXl+ryGOH2UfQyfmw1Os9IIoCEQoT099DJSPRBBaDsMWS HiRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837336; x=1691442136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mSaiqNFB6jjwG6Ld2HBVU8RlVJLDefjbnB1ExR7a8lc=; b=byfP6gWzK9d/6wctIl8aHRqCfiD+kRw5pouJOkF2SJblvugiADK4vnSowadLpkbbfZ Y9RdU9bdBDTbST9i+p1vEmIAouTmjBsQIPfRwBacElsc6IXAn3V0TqBm2GKzA+ufyAGp zWZkhZO2WarUdtLexVfLuKRlH4wTB0LaeKpYAc0jweeKBIOrFxLKqGEdjdLc6Eg5Wk/D cgFAZ6Efmo0ChP26T1XbHOGytl2tzMcIYERz0Tdgv9sfMawCUg8vhtSXQYBDhrs8ZQ/7 hY2+qcb6HCWRNh9aMih7h8v1NAvmOpENVSOtzpFP5ydn+kU3RxYPoQeNiTy3YjeWaNII H7Uw== X-Gm-Message-State: ABy/qLZQ3o6p6nUVD4vDL/orLRBwC6EtI23lcI0UVhoUELI1cqtpjXcF AMlvCNACZzshBBxH1lbTBaISQMVAqwS8de8O0A4= X-Received: by 2002:a17:902:a405:b0:1bb:660:98d0 with SMTP id p5-20020a170902a40500b001bb066098d0mr9908765plq.59.1690837336575; Mon, 31 Jul 2023 14:02:16 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 04/10] util/interval-tree: Use qatomic_read/set for rb_parent_color Date: Mon, 31 Jul 2023 14:02:05 -0700 Message-Id: <20230731210211.137353-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org While less susceptible to optimization problems than left and right, interval_tree_iter_next also reads rb_parent(), so make sure that stores and loads are atomic. This goes further than technically required, changing all loads to be atomic, rather than simply the ones in the iteration side. But it doesn't really affect the code generation on the rebalance side and is cleaner to handle everything the same. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- util/interval-tree.c | 47 ++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/util/interval-tree.c b/util/interval-tree.c index d86c0752db..f2866aa7d3 100644 --- a/util/interval-tree.c +++ b/util/interval-tree.c @@ -48,12 +48,6 @@ * * It also guarantees that if the lookup returns an element it is the 'correct' * one. But not returning an element does _NOT_ mean it's not present. - * - * NOTE: - * - * Stores to __rb_parent_color are not important for simple lookups so those - * are left undone as of now. Nor did I check for loops involving parent - * pointers. */ typedef enum RBColor @@ -68,6 +62,16 @@ typedef struct RBAugmentCallbacks { void (*rotate)(RBNode *old, RBNode *new); } RBAugmentCallbacks; +static inline uintptr_t rb_pc(const RBNode *n) +{ + return qatomic_read(&n->rb_parent_color); +} + +static inline void rb_set_pc(RBNode *n, uintptr_t pc) +{ + qatomic_set(&n->rb_parent_color, pc); +} + static inline RBNode *pc_parent(uintptr_t pc) { return (RBNode *)(pc & ~1); @@ -75,12 +79,12 @@ static inline RBNode *pc_parent(uintptr_t pc) static inline RBNode *rb_parent(const RBNode *n) { - return pc_parent(n->rb_parent_color); + return pc_parent(rb_pc(n)); } static inline RBNode *rb_red_parent(const RBNode *n) { - return (RBNode *)n->rb_parent_color; + return (RBNode *)rb_pc(n); } static inline RBColor pc_color(uintptr_t pc) @@ -100,27 +104,27 @@ static inline bool pc_is_black(uintptr_t pc) static inline RBColor rb_color(const RBNode *n) { - return pc_color(n->rb_parent_color); + return pc_color(rb_pc(n)); } static inline bool rb_is_red(const RBNode *n) { - return pc_is_red(n->rb_parent_color); + return pc_is_red(rb_pc(n)); } static inline bool rb_is_black(const RBNode *n) { - return pc_is_black(n->rb_parent_color); + return pc_is_black(rb_pc(n)); } static inline void rb_set_black(RBNode *n) { - n->rb_parent_color |= RB_BLACK; + rb_set_pc(n, rb_pc(n) | RB_BLACK); } static inline void rb_set_parent_color(RBNode *n, RBNode *p, RBColor color) { - n->rb_parent_color = (uintptr_t)p | color; + rb_set_pc(n, (uintptr_t)p | color); } static inline void rb_set_parent(RBNode *n, RBNode *p) @@ -186,9 +190,10 @@ static inline void rb_change_child(RBNode *old, RBNode *new, static inline void rb_rotate_set_parents(RBNode *old, RBNode *new, RBRoot *root, RBColor color) { - RBNode *parent = rb_parent(old); + uintptr_t pc = rb_pc(old); + RBNode *parent = pc_parent(pc); - new->rb_parent_color = old->rb_parent_color; + rb_set_pc(new, pc); rb_set_parent_color(old, new, color); rb_change_child(old, new, parent, root); } @@ -536,11 +541,11 @@ static void rb_erase_augmented(RBNode *node, RBRoot *root, * and node must be black due to 4). We adjust colors locally * so as to bypass rb_erase_color() later on. */ - pc = node->rb_parent_color; + pc = rb_pc(node); parent = pc_parent(pc); rb_change_child(node, child, parent, root); if (child) { - child->rb_parent_color = pc; + rb_set_pc(child, pc); rebalance = NULL; } else { rebalance = pc_is_black(pc) ? parent : NULL; @@ -548,9 +553,9 @@ static void rb_erase_augmented(RBNode *node, RBRoot *root, tmp = parent; } else if (!child) { /* Still case 1, but this time the child is node->rb_left */ - pc = node->rb_parent_color; + pc = rb_pc(node); parent = pc_parent(pc); - tmp->rb_parent_color = pc; + rb_set_pc(tmp, pc); rb_change_child(node, tmp, parent, root); rebalance = NULL; tmp = parent; @@ -604,7 +609,7 @@ static void rb_erase_augmented(RBNode *node, RBRoot *root, qatomic_set(&successor->rb_left, tmp); rb_set_parent(tmp, successor); - pc = node->rb_parent_color; + pc = rb_pc(node); tmp = pc_parent(pc); rb_change_child(node, successor, tmp, root); @@ -614,7 +619,7 @@ static void rb_erase_augmented(RBNode *node, RBRoot *root, } else { rebalance = rb_is_black(successor) ? parent : NULL; } - successor->rb_parent_color = pc; + rb_set_pc(successor, pc); tmp = successor; } From patchwork Mon Jul 31 21:02:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708421 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2522859wru; Mon, 31 Jul 2023 14:04:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlEc8jwHqZCuspNyVvGSETsjXqxR47p83p2/Od8MKXaOsw91cE4Nh+k2EaTssjOmgxbAbCFY X-Received: by 2002:a05:6830:12c8:b0:6b9:a84a:a381 with SMTP id a8-20020a05683012c800b006b9a84aa381mr9832037otq.36.1690837463865; Mon, 31 Jul 2023 14:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837463; cv=none; d=google.com; s=arc-20160816; b=0O2JKeQ15N3LOtlcjjDl80e/ln6s9TCT5NxaHnPjQWra0ebl/g5GIfuGebyo1wDyQZ L7ufkSG4PF3NAj36rB6UzEHWOhlbpNABZkg7jOoMh5C0YKzQQcN/vkAU85BxVi5eArJs 4rr1Yju2TVLETsroRvfsQOLmUG7rEPzakmL0TTU42VFaxc6ME4SrE/VQRcsF3ybZV4aA Lv7G0Di0IhR2wtEF0aVsnGkAmQIp/XwH6lQO8xsEJj6wSBV+xfN1dyF0/O9pL1QKhHzO Fbkajt3Kb5XR9Qmw3xeb5/5UzZsqg3lxSz33axemRtje1r1orqwHzheFG4yADAVaHIyZ Qb1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=UO4NGNMOmfX4cDWpdhP1KDrgQG8uGQRDWa46RjUxab0=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=uiZDm9dp52olvtaxKhtvJobCGWcOlVfOYE/wJvUMhIuzFrt8vb0lqpM5pbmy1nVzbN HZ018arPgII8OL0zSJHNOe24IvVvxCd395ATX31mPPSA+/uDIA34+GeYN6Z5KAEkC+f2 iSUfJrL7gATwjwizLkf/Stx2UAc6tieA83w1vV71zc4K5zIo+fKvGfcp3m9ZrdBHXoZb 7O9qfu8dy9uEZX8IqNtuNaCmS1QlGnc2mLCooiF0H0XPLh0hn1BrwZCAydlUZ/eeZJd0 axuaGVLHV7pNnDNjxqdNnWNFZeKTJVAxxdVeSGE/oPrLidkQyJdPX7pX+nXQuC66x+Vs a4cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lLMHSj3q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h20-20020a0cf414000000b0063700202615si6041965qvl.263.2023.07.31.14.04.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:04:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lLMHSj3q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa22-0000qv-8z; Mon, 31 Jul 2023 17:02:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa20-0000pg-EU for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:20 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa1y-0006Od-QP for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:20 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bba2318546so42501735ad.1 for ; Mon, 31 Jul 2023 14:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837337; x=1691442137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UO4NGNMOmfX4cDWpdhP1KDrgQG8uGQRDWa46RjUxab0=; b=lLMHSj3qBlUmoNc/cnMvH0quFXz2UGLAQWB2Ca21mMMz3X9DinqI5GGiNWduXb/Ok0 PFa9t8zmoywyregelON7qqMKy28Y6IQS4hSFkK+5BmGl6CnBDHBLPti/m11RcpEFma7I lCHlQfIe/fLoJiXeXUnyB+4v07m0bmwY3mn7ty3sdm+4WAQkLGZhwM5WbFpvG+aDClwK k0myEtR0rGLGW6uc40W/cMjRjfwM4leTFuJPBcjsSzF3ofdczXgiHRZwlkOKAa1g4jK5 0KdG4iNIbaTielT84y2ciqEd3+bPWwU2SqMvJOv7vvR/8QWe4q6bWmA/tSfvP+qriOi/ SjXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837337; x=1691442137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UO4NGNMOmfX4cDWpdhP1KDrgQG8uGQRDWa46RjUxab0=; b=ShyShCM90p41u7icxRy41jOl2hirdHAxmAbktejbdNojRXdcy3KqvYQKwWih11Onh4 ScXtHr3166hsDryCC52YE1920YMlCB4gINwbkp9sNT8xSxd6bLWQmL4ID2A9wjE/xFfR vJENw54XDb5jQxLaa5K3TsT1jpjCrvZ03v+efcn0r3sYPUEO+LlK5tJ+vagVmR5qCM+U dqj8nwUfvkTP7HU0tWuLcWylGBqSlG4Yqr8KB9YJtti2G8EHfFpHzlkddroPCYKRpssp ij8Yico984zeFTldyGnfA5g+8zHCaOZP5O6tiWO5OmtAaRwJpIT6bpy1BR3jiXbhTTvA admg== X-Gm-Message-State: ABy/qLZtGwhgd5icOuKI6h/FSwUxQp8EFgDz18UpQLeIsA5M4sN2Eujb FSqKPvVfTiKn9aKY2Cm2f4PxCOE0G7ySFjB5JNM= X-Received: by 2002:a17:902:9b94:b0:1bb:a6db:3fd0 with SMTP id y20-20020a1709029b9400b001bba6db3fd0mr9435135plp.69.1690837337383; Mon, 31 Jul 2023 14:02:17 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 05/10] accel/tcg: Clear tcg_ctx->gen_tb on buffer overflow Date: Mon, 31 Jul 2023 14:02:06 -0700 Message-Id: <20230731210211.137353-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org On overflow of code_gen_buffer, we unlock the guest pages we had been translating, but failed to clear gen_tb. On restart, if we cannot allocate a TB, we exit to the main loop to perform the flush of all TBs as soon as possible. With garbage in gen_tb, we hit an assert: ../src/accel/tcg/tb-maint.c:348:page_unlock__debug: \ assertion failed: (page_is_locked(pd)) Fixes: deba78709ae8 ("accel/tcg: Always lock pages before translation") Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 1 + 1 file changed, 1 insertion(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index a1782db5dd..b2d4e22c17 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -374,6 +374,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, "Restarting code generation for " "code_gen_buffer overflow\n"); tb_unlock_pages(tb); + tcg_ctx->gen_tb = NULL; goto buffer_overflow; case -2: From patchwork Mon Jul 31 21:02:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708415 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2522335wru; Mon, 31 Jul 2023 14:03:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlGt6stFJ4YRUMYw/Vls/sYIQ8bhPKka/cvd8BjdlyMQuqj8H6Hh1UPYzALJbgQKI5895Loy X-Received: by 2002:a05:620a:2948:b0:767:a7ac:731f with SMTP id n8-20020a05620a294800b00767a7ac731fmr12715962qkp.38.1690837394851; Mon, 31 Jul 2023 14:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837394; cv=none; d=google.com; s=arc-20160816; b=pShQwD5cwsThkcBwJOwVbpysQm9TG4pFs6fUTLsDlWmsL0Ib771owUDhmihv6AgQPE 6JPfvC/b0UJl86B7pgPoEPGRG/r84ToU05XZO6+G7TsDDkFc260CHQeiWQZDjIBPM6um 62vwb8eHM/SBfHJHLyb/qj+XkmTpRT5PeuhCXV9oolZFA+x9rZS1nVG4AAoW/1ZQ63Mj iOySNegqY2yuoKQdZFzNIaLe22jIyFRA68pspnuPmS+rAVDJn+HWqa529yHDEXvNN3KM OSmz3uq7hoN78rPKQPKxWkAczn7GKy7OFIQd1l7Jz5M6usefeHFMTc4u0XUOiyZhVvKk H1sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=i9wtzUb42CilMWSLYTGlUi5KdxK2jdYVPNnbOFMGOWc=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=QLe8TZPIZ55rCm40K9G14rZXPg8Vblufg5AoF3w/W5iB2wpzb5sYI5MsZ9OQNgn7Ee KQrVv98eNeQkZ6ge1Q7PpM5FtK/Am2Wq3MIfgGoAWRtHf7cl7351bJGcmj7YFIkZXgzE nnTd2Nc0mrbUu4ieqToAlt0ZyciaHCso+Bfib4YqIKFZsWe0ZBAZf4DHVutvLy/gqZ4b 6RDUkvSx0/+T9DSF+STPuTPLZjxoQrORUl5dHUZiw4TSBIsVn79V9z+8jFV6yNkgKdlK cYukU5iISmtHZWmK5OmPjPgd4j8FHicvj1wG7SNFX3ngbU5Fk8vvPEZKn7ARLpoVl7xd +llA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XEDB3HPo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o3-20020a05620a2a0300b00767e7fa3c7csi1133451qkp.157.2023.07.31.14.03.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:03:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XEDB3HPo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa23-0000t8-WE; Mon, 31 Jul 2023 17:02:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa21-0000ql-LT for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:21 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa1z-0006P6-Li for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:21 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bb81809ca8so39340605ad.3 for ; Mon, 31 Jul 2023 14:02:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837338; x=1691442138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=i9wtzUb42CilMWSLYTGlUi5KdxK2jdYVPNnbOFMGOWc=; b=XEDB3HPo7xsOAgetbkrHgeVGIHD+tWXWpHbTLfPNKtfEbvO5VS3c8d0q3mHYlpUh/v YN89FaJGfHDmSPXIeGR/Cg/Eca5VUbHDnwKS9o2f5cS8C+WHHzCv2UbA+0AWIDD4WB6o fidVOQRUrAQJpwd0YI11nP4fQT02B77qH4Bfy1i1KIV91MFFkaucMm8EIsTzI7LVuP5s RVXuswHeWI7UkO3IIRBHKGYrm1hKA9pEeYdysVkXO2PWCqDWPxdWjIRW+ydEyDt7vhUV ZOGg2pNpef0hEuDreTBdxrRlBoxxM1CD2w3vRXfAv8k9vQsPdnBR70NfP2DlK39b5O13 DrlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837338; x=1691442138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i9wtzUb42CilMWSLYTGlUi5KdxK2jdYVPNnbOFMGOWc=; b=hhiQPEELA7VS+xZyqAuNiezsx/zYnHh1QvtEb95h8SNij1TVOkOBlpJKIDp+99j79d qEBmIDVXo6hfq1JW4uBFgbZFO6XwttkeOHtoTqAWQtAoc9r5cJmQvG4V5F83rvIGCJmq yoCac4f0vtG9BhEq12io0XWmCQn1/iF1P1cqyCgUN+hgw3+VOHN+xmfbQJzf6vHzzg1D dEK3zKkwzO8fnj08y/kFsZRWIgdgQh3eqWtw7a1AaRZVhGOfRhY+Vv8VWTCcVom5u1iV dVTqX21GZCSo8VvEt57YnF1VwBNmWRSJx2+64dQ/ZYuu5WxYf0DJlLJEQqg9cllXjhUI ORng== X-Gm-Message-State: ABy/qLZ3lmAoKsH++3S+W7JUr9ZjPvdZ9w8vNR2ptYUENALulceZRzn8 2az/fkTm1w1jQfDQizK5Y/2CFXhTOBpbEYxOu+c= X-Received: by 2002:a17:902:c947:b0:1bb:ab0d:4f76 with SMTP id i7-20020a170902c94700b001bbab0d4f76mr14105475pla.58.1690837338186; Mon, 31 Jul 2023 14:02:18 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 06/10] bsd-user: Allocate guest virtual address space Date: Mon, 31 Jul 2023 14:02:07 -0700 Message-Id: <20230731210211.137353-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org With reserved_va, mmap.c expects to have pre-allocated host address space for the entire guest address space. When combined with the -B command-line option, ensure that the chosen address does not overlap anything else. Ensure that mmap_next_start is within reserved_va, as we use it within mmap.c without checking. Reviewed by: Warner Losh Signed-off-by: Richard Henderson Message-Id: <20230727161148.444988-1-richard.henderson@linaro.org> --- bsd-user/main.c | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index b597328118..381bb18df8 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -473,10 +473,6 @@ int main(int argc, char **argv) target_environ = envlist_to_environ(envlist, NULL); envlist_free(envlist); - if (reserved_va) { - mmap_next_start = reserved_va + 1; - } - { Error *err = NULL; if (seed_optarg != NULL) { @@ -494,7 +490,49 @@ int main(int argc, char **argv) * Now that page sizes are configured we can do * proper page alignment for guest_base. */ - guest_base = HOST_PAGE_ALIGN(guest_base); + if (have_guest_base) { + if (guest_base & ~qemu_host_page_mask) { + error_report("Selected guest base not host page aligned"); + exit(1); + } + } + + /* + * If reserving host virtual address space, do so now. + * Combined with '-B', ensure that the chosen range is free. + */ + if (reserved_va) { + void *p; + + if (have_guest_base) { + p = mmap((void *)guest_base, reserved_va + 1, PROT_NONE, + MAP_ANON | MAP_PRIVATE | MAP_FIXED | MAP_EXCL, -1, 0); + } else { + p = mmap(NULL, reserved_va + 1, PROT_NONE, + MAP_ANON | MAP_PRIVATE, -1, 0); + } + if (p == MAP_FAILED) { + const char *err = strerror(errno); + char *sz = size_to_str(reserved_va + 1); + + if (have_guest_base) { + error_report("Cannot allocate %s bytes at -B %p for guest " + "address space: %s", sz, (void *)guest_base, err); + } else { + error_report("Cannot allocate %s bytes for guest " + "address space: %s", sz, err); + } + exit(1); + } + guest_base = (uintptr_t)p; + have_guest_base = true; + + /* Ensure that mmap_next_start is within range. */ + if (reserved_va <= mmap_next_start) { + mmap_next_start = (reserved_va / 4 * 3) + & TARGET_PAGE_MASK & qemu_host_page_mask; + } + } if (loader_exec(filename, argv + optind, target_environ, regs, info, &bprm) != 0) { From patchwork Mon Jul 31 21:02:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708422 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2522940wru; Mon, 31 Jul 2023 14:04:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlEqmTtIOQ8d9FZ8HO2XLns/Rax5zRPWIYUKLOe8I4zGh4+m/2bhpdAEuySZSfE86Qt0zviY X-Received: by 2002:a05:620a:450f:b0:768:1053:b1b3 with SMTP id t15-20020a05620a450f00b007681053b1b3mr16467252qkp.31.1690837473945; Mon, 31 Jul 2023 14:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837473; cv=none; d=google.com; s=arc-20160816; b=MeBrL0Kjuh9Rrj1Lg+QKDMRUpcjhPlo+FpDTfWxIOD+s+VwKstU4ropMpno5GHek6X mDRahhQ+Ccb4opSuD3gSsz1RmP6CUcooHSVGaC0sopEd120oLflklHqJz+y/3FiFfMLk SOREZrcvBxVUp9HFL91IzkrQKwARJRGtoKCQYJ7YPOWQbDZpZCyG5EyLP3QP3MV4mpc/ JCa4FcHTh11wcCYZMmBmGjp3fQJBxDAcBBVOdbV125yvS5CRelF15hIatMKD4GpliOYS OcuNlHlCAEiNgE7yna+qyOfsttrEpettlJr2sF0DSYGnY4N80wQyi+X4HFR6e+z7ZAF0 4kkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZyEq/ubSCgSD+ft15Usf/3AynvuxUvcxwUVoiqZ43kc=; fh=Ah6H6tQOatmg8gyKeZn11fyzkkFTDqme0iqbNis7KsQ=; b=FaisJzaIa1CL6hk1VPxLoVC3wgPsNN4e83D4sAUFN0bT5YMS4kDhxI0Wf+t8JyEJQT qgCOWLhWaPsDfAxkBRT53Kt03lvFSWA7yfjeEhJccW7H3wstR4y5pS4zU34JXlj3VCib xkKd90URrsgrUFXF2+o5I1hrrzCD9n9tAZcBkRZSBWCC8FaqQQgjVQkHix1mRWVQAkp6 BCFgabhnedRrgopxwtKDqJuFJARjwvBpqKTAcGO4jxkgfmt7zVJeNMzjpPs3sXwoiqNt 3aew4leYaEDrEyODTVzJAqQUApA/Lt/WP74NHdDjMIQRwCahBeBk40CS8H/vmL2MKWeo 2fRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ToR4rD1d; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d16-20020a05620a241000b00767f1da20c3si6519432qkn.500.2023.07.31.14.04.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:04:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ToR4rD1d; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa27-0000tT-Qt; Mon, 31 Jul 2023 17:02:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa23-0000sf-Hp for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:23 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa21-0006Pc-Dh for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:22 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bbbbb77b38so29007525ad.3 for ; Mon, 31 Jul 2023 14:02:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837339; x=1691442139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZyEq/ubSCgSD+ft15Usf/3AynvuxUvcxwUVoiqZ43kc=; b=ToR4rD1dxnuU8AeOWh4/Rwnj8qj8+GYsy6kTkAG8gjufqOBCncVyYXhtNJ5Kp8W2LX cGqjldi7bdBlRdskC6II5xUHuJUyDMLO+Kaa0ENyGAIDxkWJAtgd/PH75erNQW2LhQD2 0a9JmSxTcRbddBao2ke1IV7/c2auVIldQBR5uwPLbK5um7hQLnt4C3XHgxV9HOzQPv9Z ApnMFJZuo2i4fJBqSkDKKEt2WdEMJ1eDFM4CcpJpNa6s3SUM1EVww/UCMlRxjfaNFSXT yFTWLI3wQ1R3hpA5apmd9JouHGV0jWtbZ3O/mMLB2NlxSHuaHdNBch+w+qki0/ETRXfQ F75Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837339; x=1691442139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZyEq/ubSCgSD+ft15Usf/3AynvuxUvcxwUVoiqZ43kc=; b=YUPWw+RYgjFfFI48s8xtQevJYEyTNkOAQlrfJeCiJiqQiM3IWX9CcH81Rshy4WlD75 U8zek5tGjtM9ne9xwdvuU18iv12c/PSTnnrnQVpDqV/Mfbwy9uW0bfS4+sntC0lc5IGR qOJK1qhyDAEI7PT1jgobwpgSM+Lmc3EXTcPSYfFmhal9jSaZ8HQd4CXAsHqBLP6nqkjP NGbE3xBmpVoT1q9e4RKgpS5ozy/xFCQuMkPpmjc0nIJ/xZlbN8xaiwathPmJalbjM/1m 3ap8oMduWUJE2sigIjIMg2w8niRtKldCTVS9VW2CPyskopvsjulD2IL9lJJOuZ5B1wis opNA== X-Gm-Message-State: ABy/qLbiOKJZOEMmS67Owh8FPz4FXCbiyTZz5O1/Cxe8iw4tB0PlFsPS /ET433+y3v69kY7ELZ0xAleqnanK2O6PC/x7wy8= X-Received: by 2002:a17:902:988e:b0:1b9:cc6b:408c with SMTP id s14-20020a170902988e00b001b9cc6b408cmr9995735plp.38.1690837339148; Mon, 31 Jul 2023 14:02:19 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Warner Losh Subject: [PULL 07/10] bsd-user: Specify host page alignment if none specified Date: Mon, 31 Jul 2023 14:02:08 -0700 Message-Id: <20230731210211.137353-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Warner Losh We're hitting an assert when we pass in alignment == 0 since that's not a power of two. so pass in the ideal page size. Signed-off-by: Warner Losh Message-Id: <20230728162927.5009-1-imp@bsdimp.com> Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- bsd-user/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 74ed00b9fe..b62a69bd07 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -260,7 +260,8 @@ static abi_ulong mmap_find_vma_aligned(abi_ulong start, abi_ulong size, if (reserved_va) { return mmap_find_vma_reserved(start, size, - (alignment != 0 ? 1 << alignment : 0)); + (alignment != 0 ? 1 << alignment : + MAX(qemu_host_page_size, TARGET_PAGE_SIZE))); } addr = start; From patchwork Mon Jul 31 21:02:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708423 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2523036wru; Mon, 31 Jul 2023 14:04:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlEzaMOIwVWs9acIiiXNfJC35sZqJfup6cSNUINqfRZQVCXLllBYkBiFRMZxQj2n5Lnt8Y7d X-Received: by 2002:ac8:7e83:0:b0:40e:fbfd:95cd with SMTP id w3-20020ac87e83000000b0040efbfd95cdmr4948951qtj.7.1690837485287; Mon, 31 Jul 2023 14:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837485; cv=none; d=google.com; s=arc-20160816; b=tqwoqRcX2z3s3SPUAg1mM4gnWqdzFpgsi4vN2lEDunh9WB795JTZGfqwnTi9qHkBTX eu9V+mrGGuJlOQSoa2VZmciZ0xr5xRC12akStFWzxVvK1iBcU3ifNQdKmhtcAIjTM+/R 3960KiSWEnkUPESz0+MZcHleuC7mSx93uEVRAFmd8GpNCH+GjC9F9EFND150HEK/QzPH pEgaZr8GaSzdiYrrzYMtd+6vWS9F/ldy5cW9lus9OzWs+l5ZnbCTk9iY0H4nzbrNQAeb Du0YmCMyLAE7DL9M+fXtzA3KKCnF7aCusJpxsWJX0NT+veQHk1owMxpkM80nvQUvAkvV 2LIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VHJK3pOh2Y7OF4yiI5SRsx/aGbKiHXoxnDvDxXZ5OqE=; fh=ZK20qgHUgmt1WcmFXgLjQy/QZ0FdgiHLlQ3RCScWAXc=; b=b38RH4QVgR4KyAT5PQ4rlG0CXYZmQ8JLCK9ZKXDIBZ4XcgSXAO0awlmkb4PNBctGXj UoPkI9VCYfPW+e3f7b6EJNFk3PabFzYYWn3fUbNAcgk8+7ZXBg2NXOknX9x6hHRzFq6o T8eSQOzh7417rt7fgNdhu4yGMUr/ZiSoEOajFphWhhJlOVYJLLFgTIbcrsfU3LUwQd50 bWBdaakIfqRmcOFlzfSU6/fCsCfKA5mjL5I+H655TVCYKpMnvvPJAe4dZh21ZOjUH6B2 kWaeSWu5cIMPHG3vvzp39rg12BFY/BCPM4LMuOqAsXSUwinqvE2NvPOrfNnBbkKG92Ro TvvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mx05B3VO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k18-20020ac85fd2000000b00403676c96e8si6570437qta.136.2023.07.31.14.04.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:04:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mx05B3VO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa27-0000tS-Jk; Mon, 31 Jul 2023 17:02:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa23-0000se-Ho for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:23 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa21-0006Pq-L3 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:23 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bbd03cb7c1so30983605ad.3 for ; Mon, 31 Jul 2023 14:02:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837340; x=1691442140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VHJK3pOh2Y7OF4yiI5SRsx/aGbKiHXoxnDvDxXZ5OqE=; b=Mx05B3VOYI3AT0xTAhdfgJxtDMJ3A+N7XXwJ8a0l8Ul1CaAXKIr2CQ6CgWDRVdBNtb e8hLXI/CaUEuWFyfEarC4SGqqTZHwgXuDKX4xbCTnLBSQafMSUb6CVIuBTEVWOgFjMi6 sQWKbgC4nQxHykKGy7KumQ1q2dyFcZlWT5hdE6mhjc9j0msa7JqQnvPfyfA7yczbcDEQ Wun/YRlfUgomu9TVMEzRe+7Vs2Zai+6Y/CWZCDftD0zyxK74MbOiZ/3z24wT/5YosUxt 53hCsXV6hq3A04U+QXQA+YK6sgkFdQt7+/FUyJfjY+JvZnHtuzhIKMMe37WbWwHvGtel U2mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837340; x=1691442140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VHJK3pOh2Y7OF4yiI5SRsx/aGbKiHXoxnDvDxXZ5OqE=; b=f4XZHK71gOyEj6jFRTvHnXqzYyhZ6dtXas1Rq1i1jW8OZM2gUgXRUU+jKhi4iPgGtl GMJm5u63Kmr3iknoFFCgqznu8ZuzCur7ZVv8MeisXsswvJas2tQg1uIZofuAYnpbcAK2 /J9gQSNkisssn3mmT91WliyYBuNFHN1RLf7hRAIVwsEoaL6sqe1nVvjw4DwaI6YTmaXd BYeetIy6h8vCaBcSstFh5NPZsxoCvLLli169HcjvdjNSISH3ZgdW4mubmF6F0X8rEJWg 3QnsWCm4DN2xIvUXxcudhYLP63ptqb4sA8b6QTY42ltrpACktDvrBCOlTp2fWQl6jEQq ICVQ== X-Gm-Message-State: ABy/qLYuyoFVjuQv0nP3cqHkvN30kiS10fm5rgiu66OUxoY1vYssxeqP gDiPgeQoxWQFiXx2LPiH0twaJURb5Ul0dNhKXpg= X-Received: by 2002:a17:902:dad2:b0:1b8:9b1b:ae7a with SMTP id q18-20020a170902dad200b001b89b1bae7amr11479324plx.34.1690837340145; Mon, 31 Jul 2023 14:02:20 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= Subject: [PULL 08/10] target/ppc: Disable goto_tb with architectural singlestep Date: Mon, 31 Jul 2023 14:02:09 -0700 Message-Id: <20230731210211.137353-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The change to use translator_use_goto_tb went too far, as the CF_SINGLE_STEP flag managed by the translator only handles gdb single stepping and not the architectural single stepping modeled in DisasContext.singlestep_enabled. Fixes: 6e9cc373ec5 ("target/ppc: Use translator_use_goto_tb") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1795 Reviewed-by: Cédric Le Goater Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/ppc/translate.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index e6a0709066..74796ec7ba 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -4175,6 +4175,9 @@ static void pmu_count_insns(DisasContext *ctx) static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest) { + if (unlikely(ctx->singlestep_enabled)) { + return false; + } return translator_use_goto_tb(&ctx->base, dest); } From patchwork Mon Jul 31 21:02:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708418 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2522657wru; Mon, 31 Jul 2023 14:03:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlE6rEmu9NuVNsWq/SxBS3XsSeBc2HPQcw6pJfGQR28K9k3g4jIHEx1eNrYVv5U4weI55ZCL X-Received: by 2002:a0c:aa17:0:b0:626:1ba1:70ae with SMTP id d23-20020a0caa17000000b006261ba170aemr10966962qvb.33.1690837436135; Mon, 31 Jul 2023 14:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837436; cv=none; d=google.com; s=arc-20160816; b=yunD6sFkqlMv+Bb6zDVXtLiv6SpRHOfzR4PltbLojPlYvsar1KL4VgfJLxZBnxRNoQ S9MtvVhrwG+V1PDK1ZvjH9ErBJHTx35CeMyGQsKxIL6UkQMW5pOwvukI3pQi+dzDy3B+ b5nZLlOwJoowpviUCHYad963Jfzqba37VRm3ruoC3HEBm3vhxoxFgHEsRuFlCADNNHOa lY2q+mkmNgoeEDe7lS5vNCsKCE0dIIYxHZ6v/l2Lk0ETy4fixI2xwI5mkOQCfXYm3SrO I2ctx2z4js3hNutBqScIewZsrQviqvMGRWytdJAIEkW9ZHt/ts9THZ8Y6mkQHvxeZln5 N1nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xc1zrCJDVG+lPGuHxCdmlX/jD7CzCST/l+CtotajKSU=; fh=YaYmJVj9RlRlIC1VNhWcXt1/ENbAV/0bAZn0rayUK6c=; b=gncgqdZo/Jtwr/Tk0uHZKiwzbZcs2nPV6j+aXIeA56LWAd0y9pX9A3jH/S+BEz24j0 UxsWqzx2QFIJAjA+C4ZE2g6PftspZYvuac8O5RbNwX990WO97AODPpXnzVlozZQgeJGR lkX2ppQWr0bpZykJZuR4Y3w3n/mFl7gdgCVYJgxatMvmibDSWplfk1NXU2blQiXITkb0 w/+1H9VnK+6tzYRYjOqaUHe44W/K79TL4guCiZe6mbnbYnEQEonBstz6CUMv8x8G4qRZ kytz4rZh4vrejWPU42pDbJr9vj8gYo4/cDi9PJV3QlR+6rkvkjBkJwZIrqNDm2AWJmWx xXOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uco0uNy5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s16-20020a0ce310000000b00634c07ba3b2si938744qvl.105.2023.07.31.14.03.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:03:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uco0uNy5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa29-0000uQ-2x; Mon, 31 Jul 2023 17:02:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa27-0000tV-Dn for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:27 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa23-0006Pz-EN for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:26 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-686efdeabaeso3263740b3a.3 for ; Mon, 31 Jul 2023 14:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837341; x=1691442141; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Xc1zrCJDVG+lPGuHxCdmlX/jD7CzCST/l+CtotajKSU=; b=uco0uNy5Sro7JsUIGt3LE4fx6Xu3QVpUOrYN9Lp3XDd7t+PRuwfkNTWorP/2hQMNYd ZV5Ehq1Wr3bhUIEw0zMANihsr3uFf9xhyEYU3BOKhMUngRtwHV4uXnr3i6AIrPgb66Ay SBIDDL4ObX7dBliUcTqzGvauwNkHXuOsuWwmW2OSSdVwnYmDGGMPXDJAcKlsVsp4DBtl 2dtMorR7oi1/hhlwsIOOJGGoB+9NJLA/OkYwRc4zp71HmBaWsQFYOv4ALkwxoDpJeqU0 FiA8nrps5rmCXCBchCU1wQ4V3s+gjX8wpPAxnqjJP2jCvwwdQis5cenR/lqgvuYUmkKA PugA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837341; x=1691442141; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xc1zrCJDVG+lPGuHxCdmlX/jD7CzCST/l+CtotajKSU=; b=XS10taf9A58NrVHN51h/6KSQaSOgqaNQbZp3avhVZGKkwHpCw/Kr3ciQPSAoEYfZ3T Q9rgTI+GrfPyqc7OkWPvI4b59YBPmA7jKLoBBi1uelL6YdCdi0nrEcnFflTXzy7W5Bip 3WVegZrPKa/JKY3NMGvSNqBgD93ieNg3LVRlEs58t5xWNCok0cnuOzXfphmqD3IKD4qt ksDFVBRl8HvbkKFH0Pwfe3w1XPz4lRVZeNaklbG75y8eQGKSU3eA2g4zof4aW5d/d9mW v+ho7DcMwkxjySo5SHBrqDbrgrzpse8iXJPmg1Muh1CyWw1ilX6VWMsd4qlrtmyh/q+R y5Zw== X-Gm-Message-State: ABy/qLZ2SjaJ6hcaas7ZU0AbL0KGkcBsKYO5TJj7UQuMS79qfsyaSkNC fpP50QDW9UB3sAdTw+Ni+Jk7x/IqzVb/IwY9v50= X-Received: by 2002:a17:902:9b89:b0:1b8:b47e:a881 with SMTP id y9-20020a1709029b8900b001b8b47ea881mr8368929plp.49.1690837341035; Mon, 31 Jul 2023 14:02:21 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , qemu-stable@nongnu.org, "Markus F.X.J. Oberhumer" , John Reiser , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 09/10] linux-user/armeb: Fix __kernel_cmpxchg() for armeb Date: Mon, 31 Jul 2023 14:02:10 -0700 Message-Id: <20230731210211.137353-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Helge Deller Commit 7f4f0d9ea870 ("linux-user/arm: Implement __kernel_cmpxchg with host atomics") switched to use qatomic_cmpxchg() to swap a word with the memory content, but missed to endianess-swap the oldval and newval values when emulating an armeb CPU, which expects words to be stored in big endian in the guest memory. The bug can be verified with qemu >= v7.0 on any little-endian host, when starting the armeb binary of the upx program, which just hangs without this patch. Cc: qemu-stable@nongnu.org Signed-off-by: Helge Deller Reported-by: "Markus F.X.J. Oberhumer" Reported-by: John Reiser Closes: https://github.com/upx/upx/issues/687 Message-Id: Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/arm/cpu_loop.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index a992423257..b404117ff3 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -117,8 +117,9 @@ static void arm_kernel_cmpxchg32_helper(CPUARMState *env) { uint32_t oldval, newval, val, addr, cpsr, *host_addr; - oldval = env->regs[0]; - newval = env->regs[1]; + /* Swap if host != guest endianness, for the host cmpxchg below */ + oldval = tswap32(env->regs[0]); + newval = tswap32(env->regs[1]); addr = env->regs[2]; mmap_lock(); @@ -174,6 +175,10 @@ static void arm_kernel_cmpxchg64_helper(CPUARMState *env) return; } + /* Swap if host != guest endianness, for the host cmpxchg below */ + oldval = tswap64(oldval); + newval = tswap64(newval); + #ifdef CONFIG_ATOMIC64 val = qatomic_cmpxchg__nocheck(host_addr, oldval, newval); cpsr = (val == oldval) * CPSR_C; From patchwork Mon Jul 31 21:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708416 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2522443wru; Mon, 31 Jul 2023 14:03:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlG6QRDoZjndu3kmAzpX0G//DQNHRf8KOlJzTXH477Zaf9r5VJjr5wkuaXOGVPrSAddussRw X-Received: by 2002:ae9:e606:0:b0:76c:ba0d:5be5 with SMTP id z6-20020ae9e606000000b0076cba0d5be5mr2039331qkf.33.1690837409410; Mon, 31 Jul 2023 14:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837409; cv=none; d=google.com; s=arc-20160816; b=RXuDOrDOJoDFYEIAEhYMPPepQFh8yyvpIT1WRqM+tbJUbOJjpm/lX5rCSft8LfGAzg WqyoKTJo7N6kstyzHTIuLWwUu/kpj2KFabyqboPgG9V5PgpZfk5+qWnOwe1/rwJ8hfcU 67H/h34iqCjDXwOTRn8xCt6wblN9MLpXohY/G/cggXYUaJtMe+wiOYYUGib4tEXC2Rmg By8wdSjq8kLtMVORchj0IJsWEj7R16W92ZPFiTKOpSa+uwatNAFiW0d7bqV4vSNfqVpe yVx3sYafB4SFiuHM7dK1yizN1ivXvi/dofmRk7BCzak7dQuIci5uhAByIuSYtSGyiSGW L3vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=phI5Yifm8+sVICy6zvS1SqnS1qeRxyYiP8ZIuvl4nQs=; fh=F9+CNiVJwRFefBQuaFQguBFal8jOUM389V8ndcNesT0=; b=ZsRqnHjsuZCzxsX9kPl37pzZsX2DyGA2w/dkJorBXJ9V2LoMa1M1A3hlpQy3T1CWus tDNXTjsHDbVc8ZCwoBhyYf8QIoO3sxsZr0NU8UJqysCEN3mJirERR6i3TFkWBp/LUJcw gvisnpOGvBTLwMlmho8cAGRoIR3wJpusANXg8h5sLZS6Hah+Qe+R6DGc3MSEZU/GTmUl UIgestojYwcgbPXVbm6Mp2uNOvDfNSsfW7InTpA5Zcwuj9JRClqkqLkgUUH70umbt/bo TYln/m3MMHQ6tMwxni5GSN6/lj5oF0wl6EeauPJ19GHfh36Jv+2EvT7WOw2qDrQGvQ8Z GFvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KfHqb3El; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x10-20020a05620a448a00b00767d0ec9a2bsi6809001qkp.303.2023.07.31.14.03.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:03:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KfHqb3El; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQa2D-0000v2-D7; Mon, 31 Jul 2023 17:02:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQa25-0000tF-Mi for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:25 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa23-0006QN-B3 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:24 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bc02bd4eafso17988765ad.1 for ; Mon, 31 Jul 2023 14:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837342; x=1691442142; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=phI5Yifm8+sVICy6zvS1SqnS1qeRxyYiP8ZIuvl4nQs=; b=KfHqb3El5BkLxhdzG4xvyFktdVpP40gjBUM6NITs23RNx/xJynrfsHhF8sTzPwjnor cjVZFTxtqpbRjcdJQRPPaPa88zm7HYqP5s/RU+BXpu4zgtut6gfxWJEnnCwji06goVyM Stdq19NWoFogVepSwaovXEtcb+FO4gY3fKsYCYIghSjsV7szuWCMAXRdbUuF1hUcFu0V Ug0+pP4JN987ZGtc/UgyeNGztLBqNVNx08+Yne50tuYZaA0WuUsdw5q1gndyDqK11CEF dtcfz8mgeQzyYXZz+i+o6+fOEr3cIiQ4q6+K1kSLrlNOWzW+voZT8j54xuCMK2Nh0Xaf uXxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837342; x=1691442142; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=phI5Yifm8+sVICy6zvS1SqnS1qeRxyYiP8ZIuvl4nQs=; b=XqJxReEclGdSnUH3QpEfqUEIh+Th7OL6rq6IHXtLfzREII2RAoSvzgd/3jm+98tDiM nIXa6C2qlPGwRlzvcV7CEzwhO3e+nM2O5YKB6THaTdWc7eGPvZVJ95/NqPJLwFIcoKfJ uBAgGKu0BzbOyBmJm2JxeOoK/+AuRyDk7gvixY5fnpYWw9Rz0eA5xxyPCIdjgfSu9LKq /9kVyxzN3EZY2vSS+0lcAZulu6ENdHy9HgXmBJKlOu7phg8kXX0xQR/HqtgW8MfJD8nh N9KsbeRr00aVXBDopLq+zfej4QRqStbg3CBRG0LA7mfAB5btPJcqP3WfewaXgN3mAkTo MMQA== X-Gm-Message-State: ABy/qLYrPPN9RXnZUMBvw9Dr1sUuE+9rX00zusFqcaQw/Mt71+S7ex/d 8JmhhgZbaqykdNjdroHECc0/ee6Vq3T73EW9oZ4= X-Received: by 2002:a17:902:d490:b0:1b8:a70e:8a7e with SMTP id c16-20020a170902d49000b001b8a70e8a7emr13003120plg.66.1690837341872; Mon, 31 Jul 2023 14:02:21 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PULL 10/10] target/s390x: Move trans_exc_code update to do_program_interrupt Date: Mon, 31 Jul 2023 14:02:11 -0700 Message-Id: <20230731210211.137353-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This solves a problem in which the store to LowCore during tlb_fill triggers a clean-page TB invalidation for page0 during translation, which results in an assertion failure for locked pages. By delaying the store until after the exception has been raised, we will have unwound the pages locked for translation and the problem does not arise. There are plenty of other updates to LowCore while delivering an interrupt/exception; trans_exc_code does not need to be special. Reviewed-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- target/s390x/tcg/excp_helper.c | 40 ++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/target/s390x/tcg/excp_helper.c b/target/s390x/tcg/excp_helper.c index 3da337f7c7..b7116d0577 100644 --- a/target/s390x/tcg/excp_helper.c +++ b/target/s390x/tcg/excp_helper.c @@ -190,11 +190,6 @@ bool s390_cpu_tlb_fill(CPUState *cs, vaddr address, int size, return false; } - if (excp != PGM_ADDRESSING) { - stq_phys(env_cpu(env)->as, - env->psa + offsetof(LowCore, trans_exc_code), tec); - } - /* * For data accesses, ILEN will be filled in from the unwind info, * within cpu_loop_exit_restore. For code accesses, retaddr == 0, @@ -211,20 +206,33 @@ static void do_program_interrupt(CPUS390XState *env) uint64_t mask, addr; LowCore *lowcore; int ilen = env->int_pgm_ilen; + bool set_trans_exc_code = false; + bool advance = false; assert((env->int_pgm_code == PGM_SPECIFICATION && ilen == 0) || ilen == 2 || ilen == 4 || ilen == 6); switch (env->int_pgm_code) { case PGM_PER: - if (env->per_perc_atmid & PER_CODE_EVENT_NULLIFICATION) { - break; - } - /* FALL THROUGH */ + advance = !(env->per_perc_atmid & PER_CODE_EVENT_NULLIFICATION); + break; + case PGM_ASCE_TYPE: + case PGM_REG_FIRST_TRANS: + case PGM_REG_SEC_TRANS: + case PGM_REG_THIRD_TRANS: + case PGM_SEGMENT_TRANS: + case PGM_PAGE_TRANS: + assert(env->int_pgm_code == env->tlb_fill_exc); + set_trans_exc_code = true; + break; + case PGM_PROTECTION: + assert(env->int_pgm_code == env->tlb_fill_exc); + set_trans_exc_code = true; + advance = true; + break; case PGM_OPERATION: case PGM_PRIVILEGED: case PGM_EXECUTE: - case PGM_PROTECTION: case PGM_ADDRESSING: case PGM_SPECIFICATION: case PGM_DATA: @@ -243,11 +251,15 @@ static void do_program_interrupt(CPUS390XState *env) case PGM_PC_TRANS_SPEC: case PGM_ALET_SPEC: case PGM_MONITOR: - /* advance the PSW if our exception is not nullifying */ - env->psw.addr += ilen; + advance = true; break; } + /* advance the PSW if our exception is not nullifying */ + if (advance) { + env->psw.addr += ilen; + } + qemu_log_mask(CPU_LOG_INT, "%s: code=0x%x ilen=%d psw: %" PRIx64 " %" PRIx64 "\n", __func__, env->int_pgm_code, ilen, env->psw.mask, @@ -263,6 +275,10 @@ static void do_program_interrupt(CPUS390XState *env) env->per_perc_atmid = 0; } + if (set_trans_exc_code) { + lowcore->trans_exc_code = cpu_to_be64(env->tlb_fill_tec); + } + lowcore->pgm_ilen = cpu_to_be16(ilen); lowcore->pgm_code = cpu_to_be16(env->int_pgm_code); lowcore->program_old_psw.mask = cpu_to_be64(s390_cpu_get_psw_mask(env));