From nobody Fri Apr 3 05:14:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E23E5C6FA82 for ; Thu, 15 Sep 2022 19:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229786AbiIOTmD (ORCPT ); Thu, 15 Sep 2022 15:42:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbiIOTlW (ORCPT ); Thu, 15 Sep 2022 15:41:22 -0400 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4806D9F777 for ; Thu, 15 Sep 2022 12:38:15 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id 3so13765121qka.5 for ; Thu, 15 Sep 2022 12:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=VhWltIWQGr4otQw1ais9xJMa50uESeMiXqro3LvTwg8=; b=ZOzER003YVUI0wX40DWwfYnP8PmDaWJ1GUNNHRfVg+RBqRnDWZhobIt10jbRXG8ikP 34RlHzRathp0u9FK7XGi0BLgao/yNkGHKjbQLgAQez8U/Fhwf9EYBjieRXyIlHh6xXY2 OevX6u1otUPcmldEFrNI5xLckhnjUCJ0SfDqAcm4iJwRkTv239iIvcgO2kRWb8jlWWs5 5j9nX8N+bM4li1mPoUvQv3damgywG3DWnKZ/rNZkmx3EnWm9jeo6MomLeWsIqSY88BrG D2mcSfMSddHnyLQjz6qPki3X548HVK9mZUvsHKjjIfayptk1JD4au5JFBBJkao5Oi76J ro+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=VhWltIWQGr4otQw1ais9xJMa50uESeMiXqro3LvTwg8=; b=B0w4x1aHVuJSi1N756XIaxmCSe51X7lS2eAVtzzDh1YQuRE1h633eq1XONyCbOBufA 8TShn38iIm6msqLTNhyb+Peu9te/90IoX1al6aeHwFvBUTjxC39CnWBCAznsmb2Buisa WkmnKoWDJOuMC2J+YJUYDEC9157KOGphts0sbih2Ot29ElIof8Z+w6OfClpKFn8pSHJ9 DK3wstH5KK9az6fCeO9NrFpOaPtFMrJ/L+dp0Qu1S53M2LAVuOW9FYAMAsX09P7dXWxs pOD6bBnqmZBq+LXILpllZANwIK9zyGipQk7hmiZogLleAwC/ARMYsJAtUUC3F7NfK8wR 3O3w== X-Gm-Message-State: ACrzQf0os7eFCpggmyCxTjqdjoKTBK9uWLE8x6E0U2gpgVo71dGtCw6e HEPThsYOxvB/LeNWSNhTWYagEg== X-Google-Smtp-Source: AMsMyM5HYNnkqQFryIhusPOXnsW0KKQfhvLYBxoxwi2MA6hkWp7FXfscczo+CSe0KbEGeI/30Dqumg== X-Received: by 2002:a05:620a:40c6:b0:6bb:3d30:735 with SMTP id g6-20020a05620a40c600b006bb3d300735mr1394165qko.653.1663270635403; Thu, 15 Sep 2022 12:37:15 -0700 (PDT) Received: from abrestic-xps.ba.rivosinc.com (pool-71-105-112-35.nycmny.fios.verizon.net. [71.105.112.35]) by smtp.gmail.com with ESMTPSA id r1-20020ae9d601000000b006b872b606b1sm4596459qkk.128.2022.09.15.12.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 12:37:15 -0700 (PDT) From: Andrew Bresticker To: Palmer Dabbelt Cc: Paul Walmsley , Celeste Liu , dram , Ruizhe Pan , Conor.Dooley@microchip.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Bresticker , stable@vger.kernel.org, Atish Patra Subject: [PATCH v4 1/2] riscv: Make VM_WRITE imply VM_READ Date: Thu, 15 Sep 2022 15:37:01 -0400 Message-Id: <20220915193702.2201018-2-abrestic@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220915193702.2201018-1-abrestic@rivosinc.com> References: <20220915193702.2201018-1-abrestic@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" RISC-V does not presently have write-only mappings as that PTE bit pattern is considered reserved in the privileged spec, so allow handling of read faults in VMAs that have VM_WRITE without VM_READ in order to be consistent with other architectures that have similar limitations. Fixes: 2139619bcad7 ("riscv: mmap with PROT_WRITE but no PROT_READ is inval= id") Cc: # v4.19+ Reviewed-by: Atish Patra Signed-off-by: Andrew Bresticker --- new in v3 v3 -> v4: add Fixes tag --- arch/riscv/mm/fault.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index f2fbd1400b7c..d86f7cebd4a7 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -184,7 +184,8 @@ static inline bool access_error(unsigned long cause, st= ruct vm_area_struct *vma) } break; case EXC_LOAD_PAGE_FAULT: - if (!(vma->vm_flags & VM_READ)) { + /* Write implies read */ + if (!(vma->vm_flags & (VM_READ | VM_WRITE))) { return true; } break; --=20 2.25.1 From nobody Fri Apr 3 05:14:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFE94C6FA82 for ; Thu, 15 Sep 2022 19:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbiIOTly (ORCPT ); Thu, 15 Sep 2022 15:41:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbiIOTlY (ORCPT ); Thu, 15 Sep 2022 15:41:24 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABB439F75B for ; Thu, 15 Sep 2022 12:38:17 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id r20so13725011qtn.12 for ; Thu, 15 Sep 2022 12:38:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=zpt9GCRbl8GSu+mNKxtCSxN/ut26bIT0MJANl4282eY=; b=3dVH8/YoiU0dPRG8tjjiauIameUd3EPLECdbMuaVAgYEeXgQqnkOWsfagAVQj4AyhE rYDwsvzV8Anf9tgVloy2RgFUI8qZHyJxKyKeESW9yc9Ud+AzAuvo4N8MnGjaops3ajsK lkR9nQ1iz+2cWO6g49vHE0hJjzduH94Gni1CbaKzWXGPhGn+PyeLPw5KecGYJZGqvfmR HlnUCYFrrY7x0NIpiHg6H4mXck0En0bXbhNMDnkT/2pSkphAQ8ChMha+nK2l92MIW0E/ agPr54IRRiHhKHgWkiB6uJ0fGrgrFuYVWngrJTCctsLAkCNXUsh4t+4Xm0QY6i+cO3/e WcaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=zpt9GCRbl8GSu+mNKxtCSxN/ut26bIT0MJANl4282eY=; b=QOgJoUTMMdcL8fcCb4rZqcHnf/J+IppNDdEQN6rpsNqh5IzIZh/Yku9+gTmRKj2Rae KTGGF2jLWF6cQJao4wJ1jVhQn3Yv/y0Gyhj7uvv/gNG2fgl9BS4WwIGi8AUKINvzXAHt oieswT9TdPBSdSplolOm4sWwrcJAeF3QEAd8LH3zXRLzbrHdvjdNLxx1E6niTeNrbEvc ABFo6C6eSF4vKlN8b/GzjqbEAOUPfm+uUIyME2ASrmLUun6XTCi3ydF8B4ANXr40/UcW 0BQq/RBdy7JFGJbFX/lhNGPniY1rmQwWQaQpT64ttubF2CZ87dPfyjYNNm31g8FwGb6+ JXcA== X-Gm-Message-State: ACrzQf3lrOYLInjyqo40HzXDKRJGwUBQxMRrhmAvQRXnPvpdVTdnrFL7 svXy0vWUPT/BOqNdGu6C1aFr/g== X-Google-Smtp-Source: AMsMyM4c71Uqf0BRj1ggV8j8fTpOR+nYbBIzPF9iB2m0Ng7RmJeprdOZ115YIqybBqbxLXqHItL9uQ== X-Received: by 2002:a05:622a:296:b0:35c:c846:d714 with SMTP id z22-20020a05622a029600b0035cc846d714mr1430238qtw.58.1663270636969; Thu, 15 Sep 2022 12:37:16 -0700 (PDT) Received: from abrestic-xps.ba.rivosinc.com (pool-71-105-112-35.nycmny.fios.verizon.net. [71.105.112.35]) by smtp.gmail.com with ESMTPSA id r1-20020ae9d601000000b006b872b606b1sm4596459qkk.128.2022.09.15.12.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 12:37:16 -0700 (PDT) From: Andrew Bresticker To: Palmer Dabbelt Cc: Paul Walmsley , Celeste Liu , dram , Ruizhe Pan , Conor.Dooley@microchip.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Bresticker , stable@vger.kernel.org, Atish Patra Subject: [PATCH v4 2/2] riscv: Allow PROT_WRITE-only mmap() Date: Thu, 15 Sep 2022 15:37:02 -0400 Message-Id: <20220915193702.2201018-3-abrestic@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220915193702.2201018-1-abrestic@rivosinc.com> References: <20220915193702.2201018-1-abrestic@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Commit 2139619bcad7 ("riscv: mmap with PROT_WRITE but no PROT_READ is invalid") made mmap() return EINVAL if PROT_WRITE was set wihtout PROT_READ with the justification that a write-only PTE is considered a reserved PTE permission bit pattern in the privileged spec. This check is unnecessary since we let VM_WRITE imply VM_READ on RISC-V, and it is inconsistent with other architectures that don't support write-only PTEs, creating a potential software portability issue. Just remove the check altogether and let PROT_WRITE imply PROT_READ as is the case on other architectures. Note that this also allows PROT_WRITE|PROT_EXEC mappings which were disallowed prior to the aforementioned commit; PROT_READ is implied in such mappings as well. Fixes: 2139619bcad7 ("riscv: mmap with PROT_WRITE but no PROT_READ is inval= id") Cc: # v4.19+ Reviewed-by: Atish Patra Signed-off-by: Andrew Bresticker --- v1 -> v2: Update access_error() to account for write-implies-read v2 -> v3: Separate into two commits --- arch/riscv/kernel/sys_riscv.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index 571556bb9261..5d3f2fbeb33c 100644 --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -18,9 +18,6 @@ static long riscv_sys_mmap(unsigned long addr, unsigned l= ong len, if (unlikely(offset & (~PAGE_MASK >> page_shift_offset))) return -EINVAL; =20 - if (unlikely((prot & PROT_WRITE) && !(prot & PROT_READ))) - return -EINVAL; - return ksys_mmap_pgoff(addr, len, prot, flags, fd, offset >> (PAGE_SHIFT - page_shift_offset)); } --=20 2.25.1