From patchwork Wed Jan 10 23:13:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 187110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1110986dyi; Wed, 10 Jan 2024 15:17:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEntIHoe1NNNN2CDnE0koPC0vkn3Ypdrar1VkIDwul3isszaNU8mR9CkrpoSlAzN7jDbMtA X-Received: by 2002:a17:902:d4cb:b0:1d5:5bcc:faa9 with SMTP id o11-20020a170902d4cb00b001d55bccfaa9mr325782plg.60.1704928668938; Wed, 10 Jan 2024 15:17:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704928668; cv=none; d=google.com; s=arc-20160816; b=vOcSZ7pQJpbHm5m//BxYWduuvnonn7/s0aB2d07vt4JD/rECHtlAXjA9DOBXwdzXLY DWH34wbpxwv/Eu481DpL/CytrN1Q8ZwiGUyXUb4k/2ESEkynKASjfuzzSL/WUkm4uUCL qaVSXv6TbFcXtzUNvvfehfpNVQqvel0Fn3J4ujoSTneCVrjnWgEIuNeGh+NaUKHsucsD vyKZsYEw3n3VzieClavoDIZSdqBJ/FUzjhbXz0e7HsJfo2pEoffjFJDLFrhkm6faQm9X U6affpMxKvcfOeZZZuptakJywFlM9MYKsylbpg3Go79m/tmOYSDxhX80NYZiCTBmnTSW Tr+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=C8UQElc6A/TnygdjzPZGFQnFIW5Dl3R45uxNNmzEmHk=; fh=wAXPU3FcJaKyT/S431cGy/57pKkDY1VtUcX2OXS/8Xs=; b=KO1pQLQL1jOYyvhATaSAoC9nONH7AFjX0QFgEE0GBvt/DQ1MTYLds5ez+qKuYc8UDc 0r0WDL9jEi2H9wEV1OCuPV3IZx/W6eLxbOF41tp6Z5qAAiUcpXq2UAmri6+ObtM2NADa ShW1r0jF+apAWPwSlflMXj4l7v1RPpu1KFmLmtRhx7goKh9AGWyDtr4ZysyH0xcU4c0I zdnU5iqEZz72KaaiH+BjkeQ9pVVhQ9Gmv2tokL93sCSPk2DH1RuM9qgyBQkPMklVxrBk cR4gssad6HKsiBW1IRxldx29iM48gy883FHAkhh/w3pwa9mTMAJz+VP/x8BsS3ESj+3d C9Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=eCWzhj5L; spf=pass (google.com: domain of linux-kernel+bounces-22883-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22883-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v6-20020a170902b7c600b001d46a313b41si4603100plz.353.2024.01.10.15.17.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 15:17:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22883-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=eCWzhj5L; spf=pass (google.com: domain of linux-kernel+bounces-22883-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22883-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 698EA28A93D for ; Wed, 10 Jan 2024 23:17:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E4135674D; Wed, 10 Jan 2024 23:14:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="eCWzhj5L" Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4210853E2D for ; Wed, 10 Jan 2024 23:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-7ba9c26e14aso121694339f.0 for ; Wed, 10 Jan 2024 15:14:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704928489; x=1705533289; darn=vger.kernel.org; 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=C8UQElc6A/TnygdjzPZGFQnFIW5Dl3R45uxNNmzEmHk=; b=eCWzhj5LOlysgilm3p3hoM2D6KFD4eZx5vjCAdgZmv9fXKg5cC6DTnyzktH5eTGYPp 2KFozmFlEzQx9820ultnJlepmnlZErDbSfQXFbCZEWyB5xqrDvht6hFB6I6iTuDvZ0Wi 7bTFuZyanR9KlZNxhpfHvPIjMQ3iSZjnPPdb9c3UoV528pQPG9DrpKtg0i5BiouP17+z 3r+mzQmo3GsbzaT4hLauWlv3g2LN2OqvzlVFHQun3N0rHfIBCLY9r6OmnpVFtTWD8tGm C7biSi1SmRqwtAPoQWBwmet5iCa9HM5KQlg1czEbVtmB8Wm+UGueO6UxWKHyCtjdeU12 9oAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704928489; x=1705533289; 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=C8UQElc6A/TnygdjzPZGFQnFIW5Dl3R45uxNNmzEmHk=; b=rvAj++eRdyL5Q6rxLOPU8LzcY+AnlxhhdIbooh/ddg6vDalrvhabzxHtZHtkW7FPoS g6ny4Pt581h4xTSVSqtgXIJLdNjzq5C/TfKdSxkj/UD4NmfD4pFXFXDsqzTR7RY1zhOX bmpLi/aSDJGKUb1SgodnKVr7+nRnJscnTsgsS2U0WwiMpPUqpwW20sI2383uLEIuQyOB NUCNREUW3c1mQPojAEwFhg+R7mvdrLKQXmI/48gFMsPdnQZRz/Algpm5/aPxK2FxRX2R Oy8Cpeq1uib9XjC3wcPWD8raw4NlqlXlUqJ8Ff/UiJs/xD/e2sJgBSBT8aWaM8hgnh5d f+Zg== X-Gm-Message-State: AOJu0Yxg3/DHlnsLHkUZRFtt4FKW7zfGp9JfzeSeQVznknDY/uBVIT5H tHmiRZjM7jfqFMj3Nmjpq5O31/NHaB/FAdb8umS3jDckJ5s= X-Received: by 2002:a5e:c748:0:b0:7be:c0d4:f567 with SMTP id g8-20020a5ec748000000b007bec0d4f567mr677989iop.4.1704928488783; Wed, 10 Jan 2024 15:14:48 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id co13-20020a0566383e0d00b0046e3b925818sm1185503jab.37.2024.01.10.15.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 15:14:48 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Alexandre Ghiti , Andrew Jones , Atish Patra , Conor Dooley , Guo Ren , Icenowy Zheng , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon , Vladimir Isaev Subject: [v3 07/10] RISC-V: KVM: No need to exit to the user space if perf event failed Date: Wed, 10 Jan 2024 15:13:56 -0800 Message-Id: <20240110231359.1239367-8-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240110231359.1239367-1-atishp@rivosinc.com> References: <20240110231359.1239367-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787747284109203205 X-GMAIL-MSGID: 1787747284109203205 Currently, we return a linux error code if creating a perf event failed in kvm. That shouldn't be necessary as guest can continue to operate without perf profiling or profiling with firmware counters. Return appropriate SBI error code to indicate that PMU configuration failed. An error message in kvm already describes the reason for failure. Fixes: 0cb74b65d2e5 ("RISC-V: KVM: Implement perf support without sampling") Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- arch/riscv/kvm/vcpu_pmu.c | 14 +++++++++----- arch/riscv/kvm/vcpu_sbi_pmu.c | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index b1574c043f77..29bf4ca798cb 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -229,8 +229,9 @@ static int kvm_pmu_validate_counter_mask(struct kvm_pmu *kvpmu, unsigned long ct return 0; } -static int kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_event_attr *attr, - unsigned long flags, unsigned long eidx, unsigned long evtdata) +static long kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_event_attr *attr, + unsigned long flags, unsigned long eidx, + unsigned long evtdata) { struct perf_event *event; @@ -454,7 +455,8 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba unsigned long eidx, u64 evtdata, struct kvm_vcpu_sbi_return *retdata) { - int ctr_idx, ret, sbiret = 0; + int ctr_idx, sbiret = 0; + long ret; bool is_fevent; unsigned long event_code; u32 etype = kvm_pmu_get_perf_event_type(eidx); @@ -513,8 +515,10 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba kvpmu->fw_event[event_code].started = true; } else { ret = kvm_pmu_create_perf_event(pmc, &attr, flags, eidx, evtdata); - if (ret) - return ret; + if (ret) { + sbiret = SBI_ERR_NOT_SUPPORTED; + goto out; + } } set_bit(ctr_idx, kvpmu->pmc_in_use); diff --git a/arch/riscv/kvm/vcpu_sbi_pmu.c b/arch/riscv/kvm/vcpu_sbi_pmu.c index 7eca72df2cbd..b70179e9e875 100644 --- a/arch/riscv/kvm/vcpu_sbi_pmu.c +++ b/arch/riscv/kvm/vcpu_sbi_pmu.c @@ -42,9 +42,9 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, #endif /* * This can fail if perf core framework fails to create an event. - * Forward the error to userspace because it's an error which - * happened within the host kernel. The other option would be - * to convert to an SBI error and forward to the guest. + * No need to forward the error to userspace and exit the guest + * operation can continue without profiling. Forward the + * appropriate SBI error to the guest. */ ret = kvm_riscv_vcpu_pmu_ctr_cfg_match(vcpu, cp->a0, cp->a1, cp->a2, cp->a3, temp, retdata);