From nobody Mon May 20 15:13:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1685965815; cv=none; d=zohomail.com; s=zohoarc; b=nzFCQIzA4d/EpY/7zXWlqapdXCDE63deY68UUgjiE6jikaVfeu+1ns7iMv9itNh+L9pBk1TP7MQEqPlXjKy0sgQOtuXwA+Wl9MJ1wDluPbaesyMm94SbRA0M4KTQiOJ1uNgO7jx7I7ENnQfa8B1fjV9VlSCowmf8bY3LHBv8GVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685965815; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=316QhbECLQVQvDEcbvaJgAMUNnlmjGDDN6lAPQzxncQ=; b=Xly2DUMUvO5F6JwPc6SqdHpf51n4GKMHjuZH7S0xzJgwt69c+gl42MC2cphRRRHTxt4MAer80kibetm7AzBMFfTDrlvhOffybkYZqQi/MvgtNw3jN4If6LRUCZiPgb4L6LasZ1SCNBqofF20np40m6Eka9lldGyUL+4dc3bMQ9w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685965815468958.9774143042349; Mon, 5 Jun 2023 04:50:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q68ir-0000Og-70; Mon, 05 Jun 2023 07:50:05 -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 1q68iY-0000E0-Gw for qemu-devel@nongnu.org; Mon, 05 Jun 2023 07:49:47 -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 1q68iW-0003Dv-N5 for qemu-devel@nongnu.org; Mon, 05 Jun 2023 07:49:46 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1b00ed75e34so2967035ad.1 for ; Mon, 05 Jun 2023 04:49:44 -0700 (PDT) Received: from saptrishi.. ([2405:201:d019:c279:7394:6066:fed1:a1d]) by smtp.gmail.com with ESMTPSA id n10-20020a170902968a00b001b03f208323sm6426900plp.64.2023.06.05.04.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 04:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685965783; x=1688557783; 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=316QhbECLQVQvDEcbvaJgAMUNnlmjGDDN6lAPQzxncQ=; b=PLkPaO9hvXIzPMJAebl1jRwAtOHmUViM76krP+guxGkZn3ks4igN2MRha9KFEeIIgH IaP1HTOJGa9E0TGJLri3wjNqN0r7fITfZ2sTjGGnKltWOKWWU9qSepESWMV+A7xeiI/y 0uaoH0hbFU9si7/AgiMzkUEjrZcwPBcoTTtTJgwKHkjYMyBgV4V2UQUBPM26+ow+Hw9j Ns0IsVYMSoHUHtj/vvM864QFJcZj8Uqj0QPW9os5aUbieg89Vt6JG2VSZEkOQfarfkkO F8nbp1pedyYIaLTN/575EbvTIDhhvNgSFtdRdhhGkLxiVL7JxG8rsf+Qx2i7b6UCwfHM ladQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685965783; x=1688557783; 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=316QhbECLQVQvDEcbvaJgAMUNnlmjGDDN6lAPQzxncQ=; b=AjGkAJ4i9RpMKMI05hM26MgJvyvjj6kOPvd8fXSdqaRVs3gJFlGVDnHC6uWMYir7ws pSl0Fhze0BpRvjYyYWc5Z2ZcLrMHWaui6wOMKxnApO8B5YEmWS9LEOBP2HT8gOvK/ueY NGgG7ndeb2X95RLOU4KGmTbHuF/PJ9OmmE4aDMw8Pyoo/hxF2jooj2lN3qnX8KKXbKVy CbyHa6nyz7TjNvKqMCE/Hq7sZIcrd/jnIs0L/Cc/GR23ms7wPsrqNWFcIwBn7/GWORdz vLV68mX2TyNEQgmzzwgJYdw65M8gFmhnlQAlOtP7bpvdCa1JeTw81sCebRw0aGuDS/6T hJog== X-Gm-Message-State: AC+VfDxiEcQ/ifvXjKWnv6F1EdTkCbACAxRQgn5pn0IzjZSMPgyTbFYa eWGM0k1ic8UbtwHU5Uk/DmCesQ== X-Google-Smtp-Source: ACHHUZ6a+EfYtVs/q4AdE7TfAUuSmRe0epBVPfRAU76bzyQJvrma0HKwe39EPVX6cXy6mg+5/424NA== X-Received: by 2002:a17:903:22c4:b0:1a6:e00b:c3e5 with SMTP id y4-20020a17090322c400b001a6e00bc3e5mr17693605plg.4.1685965782828; Mon, 05 Jun 2023 04:49:42 -0700 (PDT) From: Himanshu Chauhan To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Himanshu Chauhan Subject: [PATCH v2] target/riscv: Smepmp: Return error when access permission not allowed in PMP Date: Mon, 5 Jun 2023 17:19:34 +0530 Message-Id: <20230605114934.2649023-1-hchauhan@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230605075150.367555-1-hchauhan@ventanamicro.com> References: <20230605075150.367555-1-hchauhan@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=hchauhan@ventanamicro.com; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1685965816709100003 Content-Type: text/plain; charset="utf-8" On an address match, skip checking for default permissions and return error based on access defined in PMP configuration. v2 Changes: o Removed goto to return in place when address matches o Call pmp_hart_has_privs_default at the end of the loop Fixes: 90b1fafce06 ("target/riscv: Smepmp: Skip applying default rules when= address matches") Signed-off-by: Himanshu Chauhan --- target/riscv/pmp.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 418738afd8..976b199156 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -291,7 +291,6 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulon= g addr, pmp_priv_t *allowed_privs, target_ulong mode) { int i =3D 0; - bool ret =3D false; int pmp_size =3D 0; target_ulong s =3D 0; target_ulong e =3D 0; @@ -435,17 +434,12 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ul= ong addr, * defined with PMP must be used. We shouldn't fallback on * finding default privileges. */ - ret =3D true; - break; + return (privs & *allowed_privs) =3D=3D privs ? true : false; } } =20 /* No rule matched */ - if (!ret) { - ret =3D pmp_hart_has_privs_default(env, privs, allowed_privs, mode= ); - } - - return ret; + return pmp_hart_has_privs_default(env, privs, allowed_privs, mode); } =20 /* --=20 2.34.1