From patchwork Sun Aug 20 20:44: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: 715205 Delivered-To: patch@linaro.org Received: by 2002:a5d:484e:0:b0:317:ecd7:513f with SMTP id n14csp1531637wrs; Sun, 20 Aug 2023 13:44:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIPjF31+hpsV+vbBxNNxVAY1BqcCrn65A4Ryg1MUGZ64xC2QAKrMJXII4dTqp73tGplfNw X-Received: by 2002:a05:620a:2ac8:b0:76c:c20f:2d10 with SMTP id bn8-20020a05620a2ac800b0076cc20f2d10mr6154767qkb.61.1692564292592; Sun, 20 Aug 2023 13:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692564292; cv=none; d=google.com; s=arc-20160816; b=ixV4uguq2KqVaMhieXTRhO/ejFE0xTBU4M/6re1RhCmm3AhntYx2bKQVvW1oybKxWv HMEVJucz1xz/ULyGNngYzfD8RFVsfAC1Fy7ExExosVzDgby3vmhsn+32M/elpKUybBwy DGQrCP0QFhLtZsrydTP0FlZgh7+j6F2zE/3M9UNBMZDVjbHLjvac+cnu8qgsXQHFlVWb ibZUOUGCnIvAsqlt43YQbmI0TqcF6fInhnn8WC9PbdGSiv4cTO4zETXieo8UmuWPafl1 mRHms57KnYBdWyJaNgv1SAlFIcpHw1m4nrDj1H8XXP64VrHVnw0iBMV1JAtzmYMAZVRQ H3zw== 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=w5ksMQj35m+yCeIWGrGNigy7JAnPo0mf1QEQxYD2q74=; fh=VLyDSxEFBkv0vhe3LU868VMhL5H8YsEeY0KW/Q5O5ZU=; b=JrUG392mmZ6ciWf0vjqEebvvEJybabKNsuuyiBOz2objmg6HKuBAmNKL9LtiwnZZfT bjWT3A3IU1gPVIR/4vGqQZlYVW5KwEpJMOX8SpycdZFnrtvGHMHPtivyuUw/i6tprm9v fosMfJbmU3qRLCKmkJhLL4nk0Jvs+rnm1g9WHWRC9gVsdlI0jqQSNGQFEqNf4V227Xsr 2GoC0+k5fPog6dYUxoc16KeiafsxWKRC5vV5DkZqXsDkxzFd8WO2GIyGQSHbXkDd1+8J v9q6UmpO1mTxpycoPMxTNiwlZJAPjmuFlwNR3HEwkjhW3/e1X26q9My4mbz58wT408Cd caEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SuyWFW9e; 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 a17-20020a0ce391000000b00649a1860fe1si4140990qvl.399.2023.08.20.13.44.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Aug 2023 13:44:52 -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=SuyWFW9e; 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 1qXpHV-0004xE-Jc; Sun, 20 Aug 2023 16:44:17 -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 1qXpHU-0004wp-0n for qemu-devel@nongnu.org; Sun, 20 Aug 2023 16:44:16 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qXpHR-0007kS-Pp for qemu-devel@nongnu.org; Sun, 20 Aug 2023 16:44:15 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3a8506f5b73so827941b6e.0 for ; Sun, 20 Aug 2023 13:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692564252; x=1693169052; 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=w5ksMQj35m+yCeIWGrGNigy7JAnPo0mf1QEQxYD2q74=; b=SuyWFW9ej64lgYdJXhALlEdw5t87+LOrwCfZdIZu1IDlBJKfdCEb8LgNBMCy0cPYQg PpoUHuA0uB2V38JnFEcfSq0n59r54GyfswghCJvK3HjBXUT+UWbNxJkH5u+Sb2a24d7z l8i27ohh10xMH8wByxELPIpM5f0Q5hQ7uUTB/14w7Yp4sf/yhjHkn+diJk+2uNMk914I 8ZQm4+CDRUtJkS98+WUof4y3jpoIs2Gb9cDp7RZSt3vVEJeAI/ga5SVJxr4Lvmq2VZFg wxSWWz30M6GvLL6YiUFOeMrwNWRA2I1GvU72OeqJdYgyUuiM6sjIHQ0iVluJS+pJm+MC 42Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692564252; x=1693169052; 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=w5ksMQj35m+yCeIWGrGNigy7JAnPo0mf1QEQxYD2q74=; b=c4phwQfm+IDhaaHfhu0TRNd7x+kdGci19afUuthHjNi2a4E42TDGsDwp1k6oxGMUBk sAaWdw+8qXdKQj7/nXK8SBXKfpJGmDmRMxiQ4P+GVaDrPvNSpnuYDlLrjlkWg2tqFYtY SEQYbLd+4sekGp6NzJvFY7BVX6vpwKR1IappysilBp9b9B1Gk599XI7E8wIXtOgIcwn+ DaO8kY2OnQozD0zR5AO+jgvo2nEf+eFE8G1HMPEAsYfvZyxgRSoJrRZ5K33uK3tR4sMK D77A88uo87/ngnQ+h7xP9abUFKC9033gARLJaoQ+DEK5QqpD6i6xChv9RJUPpKHct9LE Y9Vw== X-Gm-Message-State: AOJu0YzP8GWSV+mwLpr9h0LIzTAJcUK2dxchIX4D7WRQHEfYPyLFVDjg BohpK7gljuho3hlalFJsWQltzA9koOwu5Eg7Dkk= X-Received: by 2002:a05:6808:2391:b0:3a4:35bb:edae with SMTP id bp17-20020a056808239100b003a435bbedaemr7899256oib.29.1692564252746; Sun, 20 Aug 2023 13:44:12 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:347d:4d37:bdd7:f5e5]) by smtp.gmail.com with ESMTPSA id c7-20020aa78c07000000b0064fde7ae1ffsm1430149pfd.38.2023.08.20.13.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 13:44:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, imp@bsdimp.com, kariem.taha2.7@gmail.com Subject: [PATCH 3/4] linux-user: Fix shmdt Date: Sun, 20 Aug 2023 13:44:07 -0700 Message-Id: <20230820204408.327348-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230820204408.327348-1-richard.henderson@linaro.org> References: <20230820204408.327348-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x234.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 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 If the shm region is not mapped at shmaddr, EINVAL. Do not unmap the region until the syscall succeeds. Use mmap_reserve_or_unmap to preserve reserved_va semantics. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index f45b2d307c..44116c014b 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -1102,14 +1102,25 @@ abi_long target_shmdt(abi_ulong shmaddr) /* shmdt pointers are always untagged */ WITH_MMAP_LOCK_GUARD() { - for (int i = 0; i < N_SHM_REGIONS; ++i) { + int i; + + for (i = 0; i < N_SHM_REGIONS; ++i) { if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { - shm_regions[i].in_use = false; - page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); break; } } + if (i == N_SHM_REGIONS) { + return -TARGET_EINVAL; + } + rv = get_errno(shmdt(g2h_untagged(shmaddr))); + if (rv == 0) { + abi_ulong size = shm_regions[i].size; + + shm_regions[i].in_use = false; + page_set_flags(shmaddr, shmaddr + size - 1, 0); + mmap_reserve_or_unmap(shmaddr, size); + } } return rv; }