From patchwork Wed Sep 22 04:56:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12509439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ED01C433F5 for ; Wed, 22 Sep 2021 05:02:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2743761038 for ; Wed, 22 Sep 2021 05:02:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2743761038 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:56636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSuON-0006SN-8b for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 01:01:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSuJN-0006VU-RS for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:49 -0400 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]:38532) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSuJL-0007f3-0Z for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:49 -0400 Received: by mail-il1-x132.google.com with SMTP id q14so1396588ils.5 for ; Tue, 21 Sep 2021 21:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i4NpgXtAEZY2117PSHLpXzBBewAezHeu7zLi+N0vW3Q=; b=su1jqUpl3ckFgHjNEtPcX2DKZMtqOi0rJeKKPKqNeY4kDym4nhQBFHY5V4vQ6YB+n5 iF00nfnVvfVlCR4G1YCiSiXIL13qCpSJ/9yXyFUoPkJz124IUkvoS2F3iy1VOey8rdOY LY0IYvvjepLduWJQ8dJOnCVldV11nGrRH6Uad2aSDMZ0qe1VGcC3Crrfk1jW2bOw7YOE 0QROKHcok8/Kxwq0qizNiUcjYjuiI90y/NcDWh6AGxzBRJKd8+RUHofE5PCSdyMvXQW3 zJJjOhyLhBtRdGhWWpwbGYjvZ1OHxiT+y4qsRHfEZMNTXo5JH1x0lFRYyCkBzBmFjOgU 2YOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i4NpgXtAEZY2117PSHLpXzBBewAezHeu7zLi+N0vW3Q=; b=8Nc9xhqZaSnvXyOIuZpeDcNFFA5JOLQLobSjaQwRpIwbdISoxkxC+MHqHqwyyp7PON lR197nFl7lxuWeuILrVIJBQv2LNV/ZPvIKsxPMMvmFSRht3Qkn4m/Lh4CugnqnjABKGv kgpvzTr5yFaV0JA/AavQZ1NllTbUtjFMIb5ykyZrXFpHwiAkA0cifAWt9XXfk3ebFOH2 4Fp9kWP5ZBgORCprTI6LcBWXnmEl+BbOnQjFNaOpMjD4M8RmPurO/k6YJSQwUGHUNCD9 jrfGjI1mS3LPT85bppxgaj4Jb7c/nkCD3R5Ui7TQvji1v2sPefCaESdfhd/RJnP67SjC wCQQ== X-Gm-Message-State: AOAM530kHCucT4sSSLuz0w8aAADAzzrs6Xzin/neyImXbsHSc090JRTS 5SsH/E+FPX/WTF7Zjr78kGz6C9uhQQ5bmoRwQFc= X-Google-Smtp-Source: ABdhPJyl+zTSfo1mKloQ5CpJNUI/vLlXu21hsgUUwBzHFoUTYBRgfTCkCKRlXWkL08Dt7xHwrXGsow== X-Received: by 2002:a05:6e02:1aa5:: with SMTP id l5mr22829146ilv.73.1632286605231; Tue, 21 Sep 2021 21:56:45 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j5sm512833ilk.58.2021.09.21.21.56.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 21:56:44 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v2 1/9] bsd-user/mmap.c: Always zero MAP_ANONYMOUS memory in mmap_frag() Date: Tue, 21 Sep 2021 22:56:28 -0600 Message-Id: <20210922045636.25206-2-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210922045636.25206-1-imp@bsdimp.com> References: <20210922045636.25206-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::132; envelope-from=imp@bsdimp.com; helo=mail-il1-x132.google.com X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, =?utf-8?q?Mika=C3=ABl_Urankar?= , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Mikaël Urankar Similar to the equivalent linux-user commit e6deac9cf99 When mapping MAP_ANONYMOUS memory fragments, still need notice about to set it zero, or it will cause issues. Signed-off-by: Mikaël Urankar Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index b40ab9045f..fc3c1480f5 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -180,10 +180,12 @@ static int mmap_frag(abi_ulong real_start, if (prot_new != (prot1 | PROT_WRITE)) mprotect(host_start, qemu_host_page_size, prot_new); } else { - /* just update the protection */ if (prot_new != prot1) { mprotect(host_start, qemu_host_page_size, prot_new); } + if (prot_new & PROT_WRITE) { + memset(g2h_untagged(start), 0, end - start); + } } return 0; } From patchwork Wed Sep 22 04:56:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12509437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D9C8C433F5 for ; Wed, 22 Sep 2021 04:59:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 01BD060F9D for ; Wed, 22 Sep 2021 04:58:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 01BD060F9D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:48648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSuLT-0000zh-7H for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 00:58:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSuJN-0006VM-AX for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:50 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]:45010) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSuJL-0007fV-G7 for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:49 -0400 Received: by mail-il1-x12d.google.com with SMTP id x2so1342400ila.11 for ; Tue, 21 Sep 2021 21:56:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4TdawYDZ/lZEP31De8eGpegR64sDlIeGOgg6kwvuUW4=; b=f8sP1VhJk4yTSYre/o0sw5Y7JYoGl8OrFPLpNXmZZ1tiLfzk5WFcafC93cf0M73fbP l/+XjVTIGbZEHOzEHBl+JMO1sshaIX4NR/b8yLdiLYWW9qFpwOoGdm45j8fojzCxGuts arCv7uxpXKPHzrFQfaXHI9jHmGqM6n/dBk0t8zPJoo3rrp86u3dcW6afaLA77DNoMfG1 BasTZgfdy4vAeGUiaNJ+ACGqiTe9d0NIOT9n+A+737K/te9NvV+VcnRhcod3Od5/7hV0 OLJlk5Ey+hmJm+grUtZaKBcBwQ7bqOHUmAZooAWtkZMf4/OGH83PM1W6JE1Vmau6542s /uiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4TdawYDZ/lZEP31De8eGpegR64sDlIeGOgg6kwvuUW4=; b=lOuWyUmexBlbT3Tptc7Z3IkyWz9YzjlH5pej0yYeJdostmDgdyBiVSTvYuRg74QuEs QBnZxBetLX9sTviNXNMn0OdKRkjBX3iy7T6R6e4DexEWEZMwTFp6aFTKziKpwubCcO/n eiohaFOqDD4EOYlS3WPmja8bcCI+/RHUQWYJNZ2rrWfT1keZcOG9XqwSmizRLEYv6tQ0 zB72nFtE1qMmiv6Dn7Zb9dolTpJ2gMAz8NNTkFf4qxso2H5kqVAAHycTaLjoOjwzAhha XhCz3V6hQyt6Jaj+bcLjde5BqY7vnkDeLN8ohrQusXdCQKDOx5UDOOPM+t1uFiekviGw yFeg== X-Gm-Message-State: AOAM532jCw9k+8Zwv8lDpEO9wXoGam8Yeac5tmW7d8xVZKJ0KQ7I0qPC kWzzBqhyt+xfQxk8ZWAm0dlLCB09h+Sc+JHTw18= X-Google-Smtp-Source: ABdhPJy+oaYZKUbmur3MBU6ifGnbcjvbVzrObik57ykHEAuOWKgHUJCMntUbrZCbPuoufAr7Qs0DdQ== X-Received: by 2002:a05:6e02:2141:: with SMTP id d1mr19602230ilv.242.1632286606036; Tue, 21 Sep 2021 21:56:46 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j5sm512833ilk.58.2021.09.21.21.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 21:56:45 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v2 2/9] bsd-user/mmap.c: check pread's return value to fix warnings with _FORTIFY_SOURCE Date: Tue, 21 Sep 2021 22:56:29 -0600 Message-Id: <20210922045636.25206-3-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210922045636.25206-1-imp@bsdimp.com> References: <20210922045636.25206-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, =?utf-8?q?Mika=C3=ABl_Urankar?= , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Mikaël Urankar Simmilar to the equivalent linux-user: commit fb7e378cf9c, which added checking to pread's return value. Signed-off-by: Mikaël Urankar Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- bsd-user/mmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index fc3c1480f5..90b6313161 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -174,7 +174,8 @@ static int mmap_frag(abi_ulong real_start, mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); /* read the corresponding file data */ - pread(fd, g2h_untagged(start), end - start, offset); + if (pread(fd, g2h_untagged(start), end - start, offset) == -1) + return -1; /* put final protection */ if (prot_new != (prot1 | PROT_WRITE)) @@ -593,7 +594,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, -1, 0); if (retaddr == -1) goto fail; - pread(fd, g2h_untagged(start), len, offset); + if (pread(fd, g2h_untagged(start), len, offset) == -1) + goto fail; if (!(prot & PROT_WRITE)) { ret = target_mprotect(start, len, prot); if (ret != 0) { From patchwork Wed Sep 22 04:56:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12509433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25E23C433EF for ; Wed, 22 Sep 2021 04:58:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8AD8611C6 for ; Wed, 22 Sep 2021 04:58:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B8AD8611C6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:48132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSuLN-0000eo-N2 for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 00:58:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSuJN-0006VQ-M2 for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:49 -0400 Received: from mail-il1-x12a.google.com ([2607:f8b0:4864:20::12a]:40655) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSuJM-0007gb-7F for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:49 -0400 Received: by mail-il1-x12a.google.com with SMTP id a20so1381234ilq.7 for ; Tue, 21 Sep 2021 21:56:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8/YbCTb4pyb9g8pcHFf9V0TExz+u9RHYfFDmfNr6nfQ=; b=42rguCYVCVvJ9vtXGpTq8ofBvAOl1yrSwdSP95Ziz+Vb7pwJZjJGUBKVDcPzqrPlDU p8Mcic7oDPB6xrf4ljJjlB6Q59aW0TPfwjorFlhiijwtirEmkLzt/h0OEYGH/gSTRPZJ RN3/rDsFpxQAnG2ydSlsacq3GWv2NTpmVMXQcCgXAdAGihDrAxm2Ku/hkBdA1h+ojkuL HS2foasqzVkwLaca2OA6S4dPSCO4zXaH7XyMzeohbpwmNGoDPfiLfw+j2/mutesZ63Qr HVaq3mVtAUeKESWpZuNi09jsD5oDYO3RlD9yN8SKjRY9lXfhmJ/746Tv9qpmk7huO8Ml IaCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8/YbCTb4pyb9g8pcHFf9V0TExz+u9RHYfFDmfNr6nfQ=; b=qJdZ+AcLBh38S2TIblLcWvpl6uZWsJHtSUpJAbsjZqdHP/Q4cD8f208kQecrKfYQQ0 yCx2OEAQK86azjqjsKX1Iu7eFwpHxR8/0rDYCP/gx7Hzsc2EmoHwDY6yLQcIcaz2AgtP VC06mmcTOKwYIPkGPTOxhbjWuRZvkGG4F3626jmcpnNibm9hhieGqxhwiNfY1lyYbYri bHe/H72JAE1zfiKQqSlc68HChDQNkogFFzNbdVUFl5M7kgkRx8zt1Nq79vKvAAIbREXj jVdgyzL8OmqHpvV7aP7JOi9Rfz1MnIxec4/WsJGiiP0BJ7fUn1lwh13BnRQWoYB7381K 9tjw== X-Gm-Message-State: AOAM533nUETz5vLKFj17xgsxUOANa8uNls+cFitmqdYS2rBE0/N0WZCk yTdPjxsxjTzFAOmI5x+0fSjderAHfqofGXpWEys= X-Google-Smtp-Source: ABdhPJxaihZetrdLz1di2lS0Q1SMQ1h1ecw743O6yZ23SjwAuzZwRnUoLn/2c+yqgh7IgOjPHQBk5Q== X-Received: by 2002:a05:6e02:20e4:: with SMTP id q4mr22039914ilv.58.1632286606738; Tue, 21 Sep 2021 21:56:46 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j5sm512833ilk.58.2021.09.21.21.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 21:56:46 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v2 3/9] bsd-user/mmap.c: MAP_ symbols are defined, so no need for ifdefs Date: Tue, 21 Sep 2021 22:56:30 -0600 Message-Id: <20210922045636.25206-4-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210922045636.25206-1-imp@bsdimp.com> References: <20210922045636.25206-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12a; envelope-from=imp@bsdimp.com; helo=mail-il1-x12a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" All these MAP_ symbols are always defined on supported FreeBSD versions (12.2 and newer), so remove the #ifdefs since they aren't needed. Signed-off-by: Warner Losh Reviewed-by: Philippe Mathieu-Daudé Acked-by: Richard Henderson --- bsd-user/mmap.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 90b6313161..c40059d7fc 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -285,13 +285,9 @@ static abi_ulong mmap_find_vma_aligned(abi_ulong start, abi_ulong size, wrapped = repeat = 0; prev = 0; flags = MAP_ANONYMOUS | MAP_PRIVATE; -#ifdef MAP_ALIGNED if (alignment != 0) { flags |= MAP_ALIGNED(alignment); } -#else - /* XXX TODO */ -#endif for (;; prev = ptr) { /* @@ -406,22 +402,18 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, printf("MAP_ALIGNED(%u) ", (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); } -#if MAP_GUARD if (flags & MAP_GUARD) { printf("MAP_GUARD "); } -#endif if (flags & MAP_FIXED) { printf("MAP_FIXED "); } if (flags & MAP_ANONYMOUS) { printf("MAP_ANON "); } -#ifdef MAP_EXCL if (flags & MAP_EXCL) { printf("MAP_EXCL "); } -#endif if (flags & MAP_PRIVATE) { printf("MAP_PRIVATE "); } @@ -431,11 +423,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, if (flags & MAP_NOCORE) { printf("MAP_NOCORE "); } -#ifdef MAP_STACK if (flags & MAP_STACK) { printf("MAP_STACK "); } -#endif printf("fd=%d offset=0x%llx\n", fd, offset); } #endif @@ -444,7 +434,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, errno = EINVAL; goto fail; } -#ifdef MAP_STACK if (flags & MAP_STACK) { if ((fd != -1) || ((prot & (PROT_READ | PROT_WRITE)) != (PROT_READ | PROT_WRITE))) { @@ -452,8 +441,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, goto fail; } } -#endif /* MAP_STACK */ -#ifdef MAP_GUARD if ((flags & MAP_GUARD) && (prot != PROT_NONE || fd != -1 || offset != 0 || (flags & (MAP_SHARED | MAP_PRIVATE | /* MAP_PREFAULT | */ /* MAP_PREFAULT not in mman.h */ @@ -461,7 +448,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, errno = EINVAL; goto fail; } -#endif if (offset & ~TARGET_PAGE_MASK) { errno = EINVAL; From patchwork Wed Sep 22 04:56:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12509435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7557C433EF for ; Wed, 22 Sep 2021 04:58:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 87A53611B0 for ; Wed, 22 Sep 2021 04:58:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 87A53611B0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:48624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSuLS-0000yx-JE for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 00:58:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSuJP-0006Y0-7o for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:51 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]:42935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSuJN-0007ic-0b for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:50 -0400 Received: by mail-io1-xd2e.google.com with SMTP id b10so1715911ioq.9 for ; Tue, 21 Sep 2021 21:56:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bz9xxzOHeyZagtkOxaSrxkXtiVjb/9po0iv6mA9969Y=; b=ONKcw7XaOEBPT0Gu4E0hvXngAxk3iOrHWOdQxFZH6UO4vChfFiT4sd7shPppDVUlmI dx1N5PkvDmlHM1HwS3Yz7fyRGxeBm+/nwLWNWU6geFkadj/SEt0Fqe5Rbba0uOM96C9C dJassA4RjbKwYHD+/FtbIJki703/YYUIXUZ+GBBuaO+eGbpw7u82HwLznZAV+hEW8fDy 1KeEaKLuJLY8qugodxas88JYE7DPfZD8Nml+PQdFkdc6P/YeBN+KbwACPOinSd0rPklN cb8U4mzIY1IhrkRUgo9nEzl+yM59YqPlYK3c48F+SLumSmp2N3vr67lzQpfI2y0llHV7 x4sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bz9xxzOHeyZagtkOxaSrxkXtiVjb/9po0iv6mA9969Y=; b=hb+8thndfLAUK+YUYes3L+q//hYW4YCu0UrCRIczSxF2KQpRHjXc5YS6EaIiB8/qaN D8bthqXz08orSDNG0EK39O/1D4wqv/747rzPyp5nKRh6U2syGSWeRE4vmm/5fc1Z72Ho JW4X/pAjvk8eswOCyFmUkOY/L5Ta8Do5ETf/hnBuuSmKEHS7DF6RiKni2zqkC0X5/PYe Zn6hbGfHKtgUzHP4lRywyE3QbqxIwx1hW0zabVjg7W1/3UDpdyrAAE7GP7vmSwjIo7X3 ql2Y2eIid/UsAF5czmkIUWMQsQy5yTtKSpdPYK/1YDknwoURrdSAE5AQb4RqnSZYhLTq S+zA== X-Gm-Message-State: AOAM530fTzTXf6+tPi0Oz4DsKq9oPlyjReXFYKay7OoLDwph56/IiI9o CsIcJ8EngWQrlU2FvzzU/DAnW5MmC9Bh7sS6kww= X-Google-Smtp-Source: ABdhPJz5WqmY0N/5gEuNmFao7zhQ4u61viAd6zM0wIlsVqRFrBJpaKs/jDfpptFfLqAGxVM53t17Fg== X-Received: by 2002:a05:6602:1346:: with SMTP id i6mr2829206iov.128.1632286607690; Tue, 21 Sep 2021 21:56:47 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j5sm512833ilk.58.2021.09.21.21.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 21:56:47 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v2 4/9] bsd-user/mmap.c: mmap return ENOMEM on overflow Date: Tue, 21 Sep 2021 22:56:31 -0600 Message-Id: <20210922045636.25206-5-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210922045636.25206-1-imp@bsdimp.com> References: <20210922045636.25206-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" mmap should return ENOMEM on len overflow rather than EINVAL. Return EINVAL when len == 0 and ENOMEM when the rounded to a page length is 0. Found by make check-tcg. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- bsd-user/mmap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index c40059d7fc..0acc2db712 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -454,11 +454,18 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, goto fail; } - len = TARGET_PAGE_ALIGN(len); if (len == 0) { errno = EINVAL; goto fail; } + + /* Check for overflows */ + len = TARGET_PAGE_ALIGN(len); + if (len == 0) { + errno = ENOMEM; + goto fail; + } + real_start = start & qemu_host_page_mask; host_offset = offset & qemu_host_page_mask; From patchwork Wed Sep 22 04:56:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12509441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5E3AC433EF for ; Wed, 22 Sep 2021 05:01:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 72CD1610A0 for ; Wed, 22 Sep 2021 05:01:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 72CD1610A0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:56586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSuOM-0006QF-GM for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 01:01:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSuJP-0006YG-9s for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:51 -0400 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]:45938) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSuJN-0007kG-Pi for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:51 -0400 Received: by mail-il1-x133.google.com with SMTP id b8so1337714ilh.12 for ; Tue, 21 Sep 2021 21:56:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6zJfAxDT5Nlo6odfG5trP7Orh8JxL9FZBJtXEayWB6M=; b=OjCLlB0TSh2qoimsRo3VWVDajLZC44Gkg+Yzq8TsDDIxWGL77C79GlEBq5p6U4lCE/ QBJY2etWxYP7PN1+oVi3sQGBfhFiTlDj4QSR0LGUa65tDBtx5QPEFASXgsmyM3rBTBGW isHP4SoxIXwEqzaaG0e44FZiUAf6ZQxH7ARBIK9ufVBn36IOS9dCoRspEtE9X4rezCDZ UyrqT4dudyVrC+vYT76wdcMWfK6Vd8hbaD5LAjBAtM3+XzMGqZvDtzgmDhe+tV8B0eJX z3ep2EfPHY0LxKtXmuDJvk34BWIFpmEFdFMMC9I4Jfx2wSyH2Czb39XlRfCRV+xu3Nhz 5Yiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6zJfAxDT5Nlo6odfG5trP7Orh8JxL9FZBJtXEayWB6M=; b=ZM4mZsX/ok4JTgJCKFPTYOUXV15HRPpMg86uW7WE9Wbp6Rz88yCMlKae0fmlJX5xLS T+0Y3JQY+fg2EgGxJ8FRVFjuyyG8vIoKOLgQfKjQuzRtcXN7zHEV/bxyLGhgnvoRCWrR P70LygIyz0GUMIIkTynjMrI3gYPHseYXtUdcPBzkYJSbqHpx7JVmF8rB/KLqQyhCn2FX cXBjKzJsaUKeekcTtkMYmcInHMoJfEXiD5mMvxxvR8ru5Y9bk6FqudX4gQlhT4ZGF82Z gbxXKckTSUoi6FVkqJKgPgx9+3j2x62Ecs5AL4W97RNF1bGnQ2z+9RclCAQU2dVHxOqD 8ROw== X-Gm-Message-State: AOAM530N4HMQwRIYcNX6DleHZRltVeURtK8kM8DJ47i60k83jp2dxfrg 765F/amC7C00OR/6LMSMEABJrpobgOHLuAQ29m0= X-Google-Smtp-Source: ABdhPJxN5TTZK4z3sRdLkg6hm/QeMEapUHD0cONnS4hSKCXLHFcbW820+XTxYVuq97xAUI4nnPODRw== X-Received: by 2002:a92:d483:: with SMTP id p3mr24619930ilg.131.1632286608477; Tue, 21 Sep 2021 21:56:48 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j5sm512833ilk.58.2021.09.21.21.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 21:56:48 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v2 5/9] bsd-user/mmap.c: mmap prefer MAP_ANON for BSD Date: Tue, 21 Sep 2021 22:56:32 -0600 Message-Id: <20210922045636.25206-6-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210922045636.25206-1-imp@bsdimp.com> References: <20210922045636.25206-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=imp@bsdimp.com; helo=mail-il1-x133.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" MAP_ANON and MAP_ANONYMOUS are identical. Prefer MAP_ANON for BSD since the file is now a confusing mix of the two. Signed-off-by: Warner Losh Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 0acc2db712..bafbdacd31 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -284,7 +284,7 @@ static abi_ulong mmap_find_vma_aligned(abi_ulong start, abi_ulong size, addr = start; wrapped = repeat = 0; prev = 0; - flags = MAP_ANONYMOUS | MAP_PRIVATE; + flags = MAP_ANON | MAP_PRIVATE; if (alignment != 0) { flags |= MAP_ALIGNED(alignment); } @@ -408,7 +408,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, if (flags & MAP_FIXED) { printf("MAP_FIXED "); } - if (flags & MAP_ANONYMOUS) { + if (flags & MAP_ANON) { printf("MAP_ANON "); } if (flags & MAP_EXCL) { @@ -430,7 +430,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, } #endif - if ((flags & MAP_ANONYMOUS) && fd != -1) { + if ((flags & MAP_ANON) && fd != -1) { errno = EINVAL; goto fail; } @@ -532,7 +532,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, * qemu_real_host_page_size */ p = mmap(g2h_untagged(start), host_len, prot, - flags | MAP_FIXED | ((fd != -1) ? MAP_ANONYMOUS : 0), -1, 0); + flags | MAP_FIXED | ((fd != -1) ? MAP_ANON : 0), -1, 0); if (p == MAP_FAILED) goto fail; /* update start so that it points to the file position at 'offset' */ @@ -694,8 +694,7 @@ static void mmap_reserve(abi_ulong start, abi_ulong size) } if (real_start != real_end) { mmap(g2h_untagged(real_start), real_end - real_start, PROT_NONE, - MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, - -1, 0); + MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); } } From patchwork Wed Sep 22 04:56:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12509443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9AECC433EF for ; Wed, 22 Sep 2021 05:02:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C3D261166 for ; Wed, 22 Sep 2021 05:02:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6C3D261166 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:57148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSuOb-0006mh-GC for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 01:02:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSuJP-0006bB-UD for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:51 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]:37775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSuJO-0007lD-CV for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:51 -0400 Received: by mail-io1-xd2e.google.com with SMTP id s20so1777398ioa.4 for ; Tue, 21 Sep 2021 21:56:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YABXt7N5hYjs3+JGLkXDo6wCkHqEJQ3WPYs4NvgmbNI=; b=7WfSY3R9j2gJ/xVYkyHeoAZkIAbIder4dOHXHJihEXvIYubYxA9zd0eMoLxbb5Sjj4 RCs4JLget78OqdlKID8yMtIFFDpRNzwCTpt/d/qcKjE4CTNhB232KIHSMeXSfw1vm7P7 jyXpFC6/Zzp/x8I80M71269w2ho4ZQfybWy89v0mvJHCJMClsvYzSvXWLEZqK2bVWDCO TAaejUj0FDby131Dvbun4DXSBEV1Nba9/C9Wzcqc5y1MfWL111ohUAHFFWVUxrfztpEg Qav2zW6Si1Vq3RNDEtxbU2plw/D8N6Mf5UryUGRBQxPxFi5lQ98esnnLvJ4Ztjhc89az JZfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YABXt7N5hYjs3+JGLkXDo6wCkHqEJQ3WPYs4NvgmbNI=; b=PaOF6vVkDZSMt09IAvIIkiZsjbK5MUsGlr25k8xJ9X+2IcrOJ0TPvkUsdwQ+DlOkEe 9V+eN9rcUo3zfn2hki9sDQnJ18lFQJZ4XG6ssQ0NeYLTbwKlqDKDfz+03JsrIcxZSw0M Ej4yJ0I79nXrauwQelP9Jki4UYmdHZ6MHM9JSIp5SBpxjZ7mkvEIkHrlePTERQxUwYw2 Rl+/a55zg70eqORJGBvUg6LqArBAZq/ejCaZ/e9RtjVTlp4ZTmMlvAv8gP26AyJd9nea F+WiGR5W08tl6SqDkidOIb1CX9t53m+j7WjhYN6iXD2gvvbGYAF+VpKrDyemU0+0skdg tyaA== X-Gm-Message-State: AOAM533UE3f7Y3hPvg8TUz4jhVGQ4a+obqldPjig6ELm07AhFkOOF85m vgHgfVqDA0LsbRWys5A+bfFYfpOg+GxNi9P5xIU= X-Google-Smtp-Source: ABdhPJyo0FvNT0+4CvayD9jMM/jGkkiKzBWemdpkHYHiEuBdPrcbGvD3qYv9kUoz6jygG1oJ76iSPw== X-Received: by 2002:a6b:f610:: with SMTP id n16mr2902215ioh.139.1632286609179; Tue, 21 Sep 2021 21:56:49 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j5sm512833ilk.58.2021.09.21.21.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 21:56:48 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v2 6/9] bsd-user/mmap.c: line wrap change Date: Tue, 21 Sep 2021 22:56:33 -0600 Message-Id: <20210922045636.25206-7-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210922045636.25206-1-imp@bsdimp.com> References: <20210922045636.25206-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Keep the shifted expression on one line. It's the same number of lines and easier to read like this. Signed-off-by: Warner Losh --- bsd-user/mmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index bafbdacd31..8b763fffc3 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -399,8 +399,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); if (flags & MAP_ALIGNMENT_MASK) { - printf("MAP_ALIGNED(%u) ", (flags & MAP_ALIGNMENT_MASK) - >> MAP_ALIGNMENT_SHIFT); + printf("MAP_ALIGNED(%u) ", + (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); } if (flags & MAP_GUARD) { printf("MAP_GUARD "); From patchwork Wed Sep 22 04:56:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12509469 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3451CC433F5 for ; Wed, 22 Sep 2021 05:05:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D6332611B0 for ; Wed, 22 Sep 2021 05:05:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D6332611B0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:35540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSuRJ-0002p1-O8 for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 01:05:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSuJR-0006eM-QK for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:53 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]:38528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSuJP-0007la-8o for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:53 -0400 Received: by mail-il1-x12d.google.com with SMTP id q14so1396755ils.5 for ; Tue, 21 Sep 2021 21:56:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8zddKgxB/r1xtG4kOIay5xz4CGP8S2d6NnpCOHxg/As=; b=lBoHbiBBOUu4SI1aGIpSm9zqNRjGHddwCJ7nr3ty5mPA/fwRmXnjEgujKZ8+d6oEd3 DHvLT3DZcizHWqrYdMrx7gayLUx0oTep2PZUBGRNxD4eW0hoiANuCRZZ/poalvFWvhWM sEkZ6AVq3wUdhvLw6Gqy1iMM26AL1UOn3CDoPUF9UkWn1+wjiH70asQx0IOgBMGO24yt 1TqTCJdAwPhIzKgVOwJWpMxTSTyAxLkZNA9NmT008dNWVs1BD/O35r9h44MsvbA0+85G r8nwi7Ok2662ym8RKiRORgaWQGrJBjHOfGB3E5Bk3FLaujYFoWo9AbIzbzOqYo55RYiZ ysBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8zddKgxB/r1xtG4kOIay5xz4CGP8S2d6NnpCOHxg/As=; b=La8OWpDqvJAC/03uZWxMw0i1AZOWdzu2+5GPMNt5CTTwowNU/A2aU08V69aaQuIHnW druH2sSloiECeK2ZGBEel/b80o51jhNyjY2iTboBK2bTPLLdbkr6rG8iGJDwybWsMFNX 0h0wU5iMMUHK43L/jc1BYCln9yQDnf646f9Q0wRNpkXL+iqGeaGEQG9gbv3gM9HJKa2j p6ldoAeGalC+XH6pCb2sD0DI7bSi5dEVSkv2HRzERrpEC0JrN0xDNy5CH37wpNAIltwG BhWtinrCG3WRG8EAfYPE24F+20DACCsMPg04fPFgmtupjPQBIiAaMgQdPj+KpKDYWXhQ S11g== X-Gm-Message-State: AOAM530wkC/Mbhx2XgeQ/mHsyIq79VN2yw6ODIP66mwn93beQvtsJGB9 PWN9v/+y3lTKSmNGDoMmtMK9zKVmZSACxc+Ahoc= X-Google-Smtp-Source: ABdhPJwKKskQv7jWSNijDaDQTDMUKv+/65ONpAnm/ZUthbLBO7PuBfIlVK3sZKEpIrDs2m8lGyFTVw== X-Received: by 2002:a05:6e02:1b0c:: with SMTP id i12mr21181150ilv.27.1632286609929; Tue, 21 Sep 2021 21:56:49 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j5sm512833ilk.58.2021.09.21.21.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 21:56:49 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v2 7/9] bsd-user/mmap.c: Don't mmap fd == -1 independently from MAP_ANON flag Date: Tue, 21 Sep 2021 22:56:34 -0600 Message-Id: <20210922045636.25206-8-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210922045636.25206-1-imp@bsdimp.com> References: <20210922045636.25206-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Guy Yur , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Guy Yur Switch checks for !(flags & MAP_ANONYMOUS) with checks for fd != -1. MAP_STACK and MAP_GUARD both require fd == -1 and don't require mapping the fd either. Signed-off-by: Guy Yur [ partially merged before, finishing the job and documenting origin] Signed-off-by: Warner Losh --- bsd-user/mmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 8b763fffc3..347d314aa9 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -154,7 +154,7 @@ static int mmap_frag(abi_ulong real_start, if (prot1 == 0) { /* no page was there, so we allocate one */ void *p = mmap(host_start, qemu_host_page_size, prot, - flags | MAP_ANON, -1, 0); + flags | ((fd != -1) ? MAP_ANON : 0), -1, 0); if (p == MAP_FAILED) return -1; prot1 = prot; @@ -162,7 +162,7 @@ static int mmap_frag(abi_ulong real_start, prot1 &= PAGE_BITS; prot_new = prot | prot1; - if (!(flags & MAP_ANON)) { + if (fd != -1) { /* msync() won't work here, so we return an error if write is possible while it is a shared mapping */ if ((flags & TARGET_BSD_MAP_FLAGMASK) == MAP_SHARED && @@ -571,7 +571,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, * worst case: we cannot map the file because the offset is not * aligned, so we read it */ - if (!(flags & MAP_ANON) && + if (fd != -1 && (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) { /* * msync() won't work here, so we return an error if write is From patchwork Wed Sep 22 04:56:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12509471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7FE5C433EF for ; Wed, 22 Sep 2021 05:05:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9883D610A1 for ; Wed, 22 Sep 2021 05:05:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9883D610A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:35576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSuRK-0002qq-Lc for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 01:05:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSuJR-0006dV-GR for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:53 -0400 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]:45013) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSuJQ-0007mz-3K for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:53 -0400 Received: by mail-il1-x12f.google.com with SMTP id x2so1342636ila.11 for ; Tue, 21 Sep 2021 21:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s72+aTPZAn9ZTqiCPxAk83JsUBHPYoFS2ZpQR76dmdA=; b=ZGcG6cgueoxFPRwolgMleYimVoUH7coFXayDGqCoMrmmH4Ph1Ou2BdOLK9IJ0j8pCY bkKD9S5iQCkPqKDxs6KfIiVyNaO4OKrMAfGmnxh33chZa0oK4neh/PcyFu77eWo+VND6 IicyIUY3nFn+ArqazBBLeotKNivRysDjgYxTwPFHapZUNeibux5GdreydBUIwrNN5OJS OXSqCvl0cbiOlWtqPd9e6SEPiuAUWzKEpIF8snrBXks1qvo/qDXxMnzMW2Y0LJDlJ/2P LRqVMXCONRNJe6L4Lp/gsWs8h03b/Z7VXZAzA6CexH1k8rsAu0ERxqLvOzyWVP04RLJn DvAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s72+aTPZAn9ZTqiCPxAk83JsUBHPYoFS2ZpQR76dmdA=; b=dDzECK6sY7c3xH3dSlWHc/Uhcnitm6jHz3bDjJYs0K8J8fObv86Ut+7kU2p5j2vpyi DM0MRICTjUNLWFRWwSoDYk5bCd35IkzgiYPpERAX0SomWUzhOLadW1rLeFRsysesUblW wMtN4My4RwlMhkICV0RbufIZRZL9KJiXOkgSSZvoXQNLLN4GYOeibNQNp5QVNB6kfRZH Oo30poN71eFEO8S8D7mrIm+M1nUmX46Y5afKpXZVbts9XZbMuiwn1kAq2l/MWvF95zWN bLQpF3M5tTx/XMvd8lod8N4KILJ1lTy+pmHwPo03j39sEvEFZnJIbza7jzYfNc7INLq5 RNjA== X-Gm-Message-State: AOAM532ciQ0TyRMEqKBURxe3aO1Gh4maT+TuDbVevDDiynj3q0okIPSu 3PF6cFoiLQCeZSnOFdhYT98QBhFRjZxJbyghqJg= X-Google-Smtp-Source: ABdhPJxM5MvX2Y8NazTti1X96mQ/dSjgf7MYv6IT/juf12WFJz0DYoj59n+J14BHxVvSZ0PjeooSMA== X-Received: by 2002:a92:b301:: with SMTP id p1mr23088388ilh.10.1632286610783; Tue, 21 Sep 2021 21:56:50 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j5sm512833ilk.58.2021.09.21.21.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 21:56:50 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v2 8/9] bsd-user/mmap.c: Implement MAP_EXCL, required by jemalloc in head Date: Tue, 21 Sep 2021 22:56:35 -0600 Message-Id: <20210922045636.25206-9-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210922045636.25206-1-imp@bsdimp.com> References: <20210922045636.25206-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12f; envelope-from=imp@bsdimp.com; helo=mail-il1-x12f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Kyle Evans jemalloc requires a working MAP_EXCL. Ensure that no page is double mapped when specified. Signed-off-by: Kyle Evans Signed-off-by: Warner Losh --- bsd-user/mmap.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 347d314aa9..792ff00548 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -387,7 +387,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size) abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, int flags, int fd, off_t offset) { - abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len; + abi_ulong addr, ret, end, real_start, real_end, retaddr, host_offset, host_len; mmap_lock(); #ifdef DEBUG_MMAP @@ -599,6 +599,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, goto the_end; } + /* Reject the mapping if any page within the range is mapped */ + if (flags & MAP_EXCL) { + for (addr = start; addr < end; addr++) { + if (page_get_flags(addr) != 0) + goto fail; + } + } + /* handle the start of the mapping */ if (start > real_start) { if (real_end == real_start + qemu_host_page_size) { From patchwork Wed Sep 22 04:56:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12509445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E85D6C4332F for ; Wed, 22 Sep 2021 05:02:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B426B61038 for ; Wed, 22 Sep 2021 05:02:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B426B61038 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bsdimp.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:57150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSuOb-0006ml-Tj for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 01:02:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSuJS-0006fs-BY for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:54 -0400 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]:46855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSuJQ-0007oY-RG for qemu-devel@nongnu.org; Wed, 22 Sep 2021 00:56:54 -0400 Received: by mail-il1-x130.google.com with SMTP id h20so1325226ilj.13 for ; Tue, 21 Sep 2021 21:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j/SZajdj1q4GBzUgoYeNuK9i6EevpvYpkOKU5eddA5M=; b=PdCadxxVB9ZgYS2Qvtkcd98GiTg19qWVhucKwUQ4az4nzjzc+KP6xOADCN3nBYx4bw 822PRBhfzlmyvkT8XDlhw9MCLMHczbRxAseqd54WYJHImXBvWiICxvF9QRsQmGQJ3V8X 1I+eK10fy2ZpdpstrNmTtoqEbhTFKZP73b//g3V7fli3WYa4IlhFIJ6CM7iqgLzwgQwy dZrQ4H1gxxeb7gOJfi0qSaCsMtqh1pSBdyQvN6oYPgp4LS2qAay69AZ/ex6IAkl1qwy2 XQYoZm2kBb2Zvze40RXGYLvUuTWJmY1N4DegmxF5bU/g8JYMLDjyC4lomm0yNFHl/wNN pwPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j/SZajdj1q4GBzUgoYeNuK9i6EevpvYpkOKU5eddA5M=; b=f4i9vnZtvYdoa1Sf+PgqLrAp7kj6XNpasPCRn6xOg8IOCPJvMa4wfLSbIBXU/7tg3t 2EpRHMgXr/DmKmgMXMkTPwgIO38SnSR3WmuVJHE73umGTm6o0DM7z2GMuZ2gqLbMtA9A 9iDBHub8t1DS/nW3aGuBaN/K5LARZGKnE9X8HlHLV3d6hgFwdc6U4qxWRQIfAlyiWBS/ 4NC6M7r3gyxfS5AjmoRg3zA7Lv9ETHiGnsVQehc7zeUmXEJJYJTa9KmIRLpfF7Qt5yhb 0pzAgKoA5ivt/oBWPlP5S3giHSUjKBy14Nq3lAdS4YVYjUeUJD6GO4ss4LyhizvxSHsI WBvA== X-Gm-Message-State: AOAM531FPrmMBykS8U2HBt2+KMNANkWHafmKlaPEKc0qt2YGHIvHTorQ 7t2spRYZrBGKl6k6u7DVU0UTbit3gQOYvyvytbE= X-Google-Smtp-Source: ABdhPJwUOAU3qzH2qx7D6VBr4s+eLcgG9WmP9DNX+PqvCOyuM1MZXSsb3FqqeyWj4fMxxb42TVeR5w== X-Received: by 2002:a05:6e02:1a84:: with SMTP id k4mr16745287ilv.146.1632286611527; Tue, 21 Sep 2021 21:56:51 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id j5sm512833ilk.58.2021.09.21.21.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 21:56:51 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v2 9/9] bsd-user/mmap.c: assert that target_mprotect cannot fail Date: Tue, 21 Sep 2021 22:56:36 -0600 Message-Id: <20210922045636.25206-10-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210922045636.25206-1-imp@bsdimp.com> References: <20210922045636.25206-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, =?utf-8?q?Mika=C3=ABl_Urankar?= , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Similar to the equivalent linux-user change 86abac06c14. All error conditions that target_mprotect checks are also checked by target_mmap. EACCESS cannot happen because we are just removing PROT_WRITE. ENOMEM should not happen because we are modifying a whole VMA (and we have bigger problems anyway if it happens). Fixes a Coverity false positive, where Coverity complains about target_mprotect's return value being passed to tb_invalidate_phys_range. Signed-off-by: Mikaël Urankar Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- bsd-user/mmap.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 792ff00548..4ddbd50b62 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -591,10 +591,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, goto fail; if (!(prot & PROT_WRITE)) { ret = target_mprotect(start, len, prot); - if (ret != 0) { - start = ret; - goto the_end; - } + assert(ret == 0); } goto the_end; }