Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4975524rdb; Sat, 30 Dec 2023 00:02:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZKuwvXSi661nkF04ANq1ew4CaoXpbWIAS3jChkguNdTQ4Lo4z/3OsiH1jyBd24xUDOcv6 X-Received: by 2002:a05:6a21:32aa:b0:196:6e79:17b8 with SMTP id yt42-20020a056a2132aa00b001966e7917b8mr3436943pzb.97.1703923325745; Sat, 30 Dec 2023 00:02:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703923325; cv=none; d=google.com; s=arc-20160816; b=ePRscO0CEK4HAf43ua2tkWogezMOntxQvnSBKXvChB14b2R0qdwE5ZDpeH1ELCa/2P yiy4SPUXxrkQ4uu3Su4KIuLqGo9oyUmXpxpZSCUesSfUT5evZpYlFsTTCL28fl/rX+rA 0pF/YzP88clg/ZXmlapa70B0G7INKVsuTtQ8GHPLJtaGpc5M6q8cuXYlPQE3gvPYp57Z re1fBiJgfbe0/h05r0yCWoj4aUZNGv/sRHZ4sSsZT5cZrLSbxIBnI/n6uQUsGwoTXK1V gwyY9pLveTViyXNgulWFAWMFsgiUpMzhAzHqXYaIXheshUnBKM71i5tcns8Ag3rSJ2K5 Z42Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=LPf6Z8tNoGfk9MBYZ1RUJvDaaG9qPZRvtU/U6N7KNnE=; fh=FsN7YI7vtCi1XL+rgBNsdMzf1zwrS55wZ61JkiQB8AM=; b=DQT54IejniFlxsm/PpQnPVKubu41l8DgBGhblN6rc/oElFz6tU5S3hIOFMdF1Mpde0 lRy+Hd8Sb6arp3reBVCPbVdi1KcbqpQs0WGfrXSteASdDI1Yo+phS4il18jsXL6C13Ib 1ouSMCxP2ZdMv+jDfzOX/h853NKEjIsBNYgBk6dELOMsTT6HY8Hp/zQr7XOvMhfHZfjB 5UiTV27rQ8b9ch62NiJE2S9cBrKrsQyyuv3Q0jrd5ZFOPcjWwbd8yT5C0sBuDX8OeOaG qjYdhe46St+I8ordsbpyIG5V5CPHiO9NOIf7vQPirN5c2FpyeZczbz8yFEkNJU1dITfo hdWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=ckBfBUTK; spf=pass (google.com: domain of linux-kernel+bounces-13358-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13358-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ds10-20020a056a004aca00b006d9bd0e0c60si9112095pfb.324.2023.12.30.00.02.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Dec 2023 00:02:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13358-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=ckBfBUTK; spf=pass (google.com: domain of linux-kernel+bounces-13358-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13358-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 297E6B21507 for ; Sat, 30 Dec 2023 08:02:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CEFFF8F47; Sat, 30 Dec 2023 08:01:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=brainfault-org.20230601.gappssmtp.com header.i=@brainfault-org.20230601.gappssmtp.com header.b="ckBfBUTK" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) (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 16D028BED for ; Sat, 30 Dec 2023 08:01:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=brainfault.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=brainfault.org Received: by mail-io1-f51.google.com with SMTP id ca18e2360f4ac-7b7d55d7717so352468039f.2 for ; Sat, 30 Dec 2023 00:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20230601.gappssmtp.com; s=20230601; t=1703923306; x=1704528106; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LPf6Z8tNoGfk9MBYZ1RUJvDaaG9qPZRvtU/U6N7KNnE=; b=ckBfBUTKsPKnbFcdr3E7+Q4lBxFoRTmMzFCEiz4urib9eotQZgmMlP01J8Egb9qkKM 7klC0kKQ/ExMWvtdXv5mVvQDZzXTLjCeUZS5BcRxvU28dXf7eAZKzhrl2uslOZOpfODd sgYAjKGgQXbQOiDH9OyUX00EOa0fsx8Al/lMY9pvH/qBU+rSREru3VAOr8iDRYtLcnAD F++WdSBqaI2ssbRzzkl7LFBODmDeKbRwqDltfFNK0jS2XLh38UFYz9qpTuDBYzNM4APm vFaa/ngt0uUtV0dJcrILmlH+uinP880j9pSYZw6DwXt+gI14caXv7khUT7dczByMCiOu sFYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703923306; x=1704528106; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LPf6Z8tNoGfk9MBYZ1RUJvDaaG9qPZRvtU/U6N7KNnE=; b=HvvIbpcEeoXI5euUTKdl8D5/wkdQsWXFhfkyrh1Jq7FPJKdD3crZdP7pk7SYgtz74E VVdhKVamMuxwms6ETI9coxTtt1+wRd8rnNEryQm0x01SVgmSG3Xwn/nge02qAG6yKw9t RJKSKQWuszR/xVzepKET7Fl3DzVaRjcJB9mQFnJF2yuij9u4hvnNCw8fcn/+/hOkd4g4 ybOHcAvNzKEgS3gcH6NGLiZ2lqLcOZlLMHAvK+YbDDkUXAI6T14qE4WLOJ9d5Q3oPmrn lqv5w164tNneFh/Pammne7WgWWEu0plst7g2Rv/UySeiPQzz6X2hnqo/oBGY0Zy4J5Q2 ATtQ== X-Gm-Message-State: AOJu0Yxr9MFYDUacbiYs3wYTmcil34Y3ea+2K/hJJZP9o4nkZBTaXEXg N8KX+0ufRpnIOIes9liWDd6R66uz5rzzHbSIiDQlN0uNK94PcBYp7Umg4dKhcLM= X-Received: by 2002:a92:c549:0:b0:35f:ee15:742c with SMTP id a9-20020a92c549000000b0035fee15742cmr11876530ilj.7.1703923306083; Sat, 30 Dec 2023 00:01:46 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231229214950.4061381-1-atishp@rivosinc.com> <20231229214950.4061381-8-atishp@rivosinc.com> In-Reply-To: <20231229214950.4061381-8-atishp@rivosinc.com> From: Anup Patel Date: Sat, 30 Dec 2023 13:31:36 +0530 Message-ID: Subject: Re: [v2 07/10] RISC-V: KVM: No need to exit to the user space if perf event failed To: Atish Patra Cc: linux-kernel@vger.kernel.org, Albert Ou , Alexandre Ghiti , Andrew Jones , Atish Patra , Conor Dooley , Guo Ren , Heiko Stuebner , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Dec 30, 2023 at 3:20=E2=80=AFAM Atish Patra w= rote: > > 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 samplin= g") > Signed-off-by: Atish Patra LGTM. Reviewed-by: Anup Patel Regards, Anup > --- > 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 8c44f26e754d..08f561998611 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_p= mu *kvpmu, unsigned long ct > return 0; > } > > -static int kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_ev= ent_attr *attr, > - unsigned long flags, unsigned long e= idx, unsigned long evtdata) > +static long kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_e= vent_attr *attr, > + unsigned long flags, unsigned long = eidx, > + unsigned long evtdata) > { > struct perf_event *event; > > @@ -455,7 +456,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 =3D 0; > + int ctr_idx, sbiret =3D 0; > + long ret; > bool is_fevent; > unsigned long event_code; > u32 etype =3D kvm_pmu_get_perf_event_type(eidx); > @@ -514,8 +516,10 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu= *vcpu, unsigned long ctr_ba > kvpmu->fw_event[event_code].started =3D true; > } else { > ret =3D kvm_pmu_create_perf_event(pmc, &attr, flags, eidx= , evtdata); > - if (ret) > - return ret; > + if (ret) { > + sbiret =3D 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 *vcp= u, struct kvm_run *run, > #endif > /* > * This can fail if perf core framework fails to create a= n event. > - * Forward the error to userspace because it's an error w= hich > - * happened within the host kernel. The other option woul= d 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 =3D kvm_riscv_vcpu_pmu_ctr_cfg_match(vcpu, cp->a0, cp= ->a1, > cp->a2, cp->a3, te= mp, retdata); > -- > 2.34.1 >