Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1725888lqz; Mon, 1 Apr 2024 15:37:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX/vweOhtmB/YNYHVUzvri73uuztC4AE9nr2ri8cvqKddjhrChRnRE3kpFKbL1f35rHbmY9v3ZviySkTjoGaLgoXyvjmAURZUCPjFWBHQ== X-Google-Smtp-Source: AGHT+IFTEEvZFYUqT01aWvLsUs8jpXVSu42l9A4WmXDEyMGlUDX+uBZvWEy7pBYfRCCKq4ljbTe/ X-Received: by 2002:ac8:7f11:0:b0:431:5e0b:e5e1 with SMTP id f17-20020ac87f11000000b004315e0be5e1mr20651032qtk.4.1712011047641; Mon, 01 Apr 2024 15:37:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712011047; cv=pass; d=google.com; s=arc-20160816; b=o52isIr6JyIhagtQm9wyDBFTWMgvil8S8v8Vw4b8slxPe1wZhV2pXBop4QdRMWEcRA hc9H9CXh30qWsoEiQleS728SZnL1DI1B7B8238PK6sQJxR7H4YawE2UC6+QIocPI4KpW AABMQLcbVOAyM01J7xMpxNbL819Rt0UwT47vqd47kayDRZ13SXGxlVjP2sJD4+R/0FKc BZxugqu3Lj+K3IPTrpcSDtWBI3ksc/syqJ8XKe3bcbeB4fbBNofDJM91uTHPey1dZaSu 9ywi8yWNxykVes0yFAH5suXTzdnEKiMhNAWvzRIrgnhxd2vlJFiGSOf71ZnRcLWbJJwb eS3Q== ARC-Message-Signature: i=2; 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=aY4S4yPUfIj0lcZIhHGm/I+32cExDlXkzSV19aujdnE=; fh=F/y3BeJ9/RWEMJRezClfmAObZZc8WUqOn0ZQ4hj0/sI=; b=ikeZ7Rd0cNGsIwDHaQTQkMNCwR+tYAxwGkMZPQ0OKLYd+uRfkkjYxJzhahBiFPz9iP hfxVtUz7A52Vtm+7w3F05hxSgBNMDSIjaVUc2a4VTC38RfJJz7IkB4Dhux6HS4Z4w87m dEps1dTnQzQ6RioiTbeUUmcDjmXf0ON5XTqT3lBFSJIK7AeI4X0Nuf0FfjiIERKzOIJ2 19A2ap7vXABUZqmvo+NHdETfI/RAv7x+nF1TDKf4qgHWLnI7fujZdwMvOX6U1TbkYMh8 GZfjRRnxVcVeEpMPO7qwFhtWBgukIndRkXoiORPN3JM/7oO25gxOvLelnIy8DRvSNNd/ cM/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=OEmtXUxR; arc=pass (i=1 spf=pass spfdomain=atishpatra.org dkim=pass dkdomain=atishpatra.org); spf=pass (google.com: domain of linux-kernel+bounces-127139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127139-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n12-20020a05622a11cc00b00432d75bcb77si4815442qtk.520.2024.04.01.15.37.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 15:37:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=OEmtXUxR; arc=pass (i=1 spf=pass spfdomain=atishpatra.org dkim=pass dkdomain=atishpatra.org); spf=pass (google.com: domain of linux-kernel+bounces-127139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127139-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5D6A11C216B2 for ; Mon, 1 Apr 2024 22:37:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2479F56B64; Mon, 1 Apr 2024 22:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=atishpatra.org header.i=@atishpatra.org header.b="OEmtXUxR" Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 5B99F29CFA for ; Mon, 1 Apr 2024 22:37:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712011036; cv=none; b=lxX8cpVOV1gD4gnzTEJ8hmFWKFDcBmuFtLhEC+3ysEkjrTEoXQ8WrQnNjC3rESsjQ9ff0zQmojuhXa5raidUjXSOEHpzHu1NanDJNfRCzazVumhGE96/FcNZr1R2IRfqxzfpf/GVIHH8Zf9PnRoqWEj7DC1G1MzMsy/gxytqqlw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712011036; c=relaxed/simple; bh=NTg0LNvASPU60r1Pc8Xg21cU9Db2pDu0bl/8+t+KWZg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=jj51cbYrDxj2pwwQ4uPm7U/Pvd81DII3TyXdZvcHPO9WEgaposbL+mIwzflB8Au6nxUqEzS7hliKPwX9zn58PIDIQJIf44yRil60c6C0W4fIcnsbods76lr/trkvZF3gYilKftyKnDhAgs6x5Ds0NtFc6DcylNSYkzUO2v0qcHs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atishpatra.org; spf=pass smtp.mailfrom=atishpatra.org; dkim=pass (1024-bit key) header.d=atishpatra.org header.i=@atishpatra.org header.b=OEmtXUxR; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atishpatra.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=atishpatra.org Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d48d75ab70so66019031fa.0 for ; Mon, 01 Apr 2024 15:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; t=1712011032; x=1712615832; 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=aY4S4yPUfIj0lcZIhHGm/I+32cExDlXkzSV19aujdnE=; b=OEmtXUxRtFiXZW6cQjKo9p5rXSTBp/6P8FcepU+kL8H3t5v7zCxK8XLDgALUHeKAqQ 8H7oNeNCGwmMmEchSDVVdnkeOZFZz0ExUvy4rRbVhXnC0RuYkpJUaKwmsDHlxDUj5xsA LaGACyClK2phAkDZxwFvBVuXisHlB8q+imrvk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712011032; x=1712615832; 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=aY4S4yPUfIj0lcZIhHGm/I+32cExDlXkzSV19aujdnE=; b=qlHBJA6HOEMp7qsZGz98N9T1a/t/APPNGztHLHFOoB0geSDx1tQ4U4aZr/NWoeG4J9 Imun7/Tc/LvZJlvQNLel/lD6tM+UTWx4a5nQkTeFwlzh3X/Jak8F7i7RYl6aArqkNzTr eR065+A+W+yZcH8zSoq5CtOf6oI2slU1P+Ben6pfaljDkJjTQRT6ihsXVB56a92MNiiX lc+r8lAMzEdprH5c/Dfg2eU05Vh6H+K94RaitXWLXpvl6vdQfQhOcCYlWfIatfg8GSlp zbstIYP9wx7YfiVECfD8Z3aTGBaEiUzLrhVDVpwAIRj659adA8wnGwVikwDZl1qls56P OafQ== X-Forwarded-Encrypted: i=1; AJvYcCUBAjwro847QupqZl97SkxR9ACdBE4mz/kh6cSQk5Uakas5EwXqEHWH/SXI1TyXVIDOY939+aR5R50CM4oLnKeRtSZZmvhH25/yxCyx X-Gm-Message-State: AOJu0YwLUrV8l4J9qMcf+TxkzLt4EvCvNFr37tFLNuCxVXSeeNPOigjW ikgLBdOkgQ/pvvYUBipl78aipzKJPUsF/VhEefMED3dgb8qeg4tjo0P5DTODTjHDAnQafGPX0iJ AEX1WJ3YD/p13foToV5YT6ZqDdAvYv7lokXyF X-Received: by 2002:a05:651c:14a:b0:2d4:514b:428 with SMTP id c10-20020a05651c014a00b002d4514b0428mr6412640ljd.6.1712011032590; Mon, 01 Apr 2024 15:37:12 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240229010130.1380926-1-atishp@rivosinc.com> <20240229010130.1380926-8-atishp@rivosinc.com> <20240302-1a3c0df25f2422e1e6abecf3@orel> In-Reply-To: <20240302-1a3c0df25f2422e1e6abecf3@orel> From: Atish Patra Date: Mon, 1 Apr 2024 15:37:01 -0700 Message-ID: Subject: Re: [PATCH v4 07/15] RISC-V: KVM: No need to exit to the user space if perf event failed To: Andrew Jones Cc: Atish Patra , linux-kernel@vger.kernel.org, Anup Patel , Albert Ou , Alexandre Ghiti , Conor Dooley , Guo Ren , Icenowy Zheng , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , Will Deacon Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Mar 2, 2024 at 12:16=E2=80=AFAM Andrew Jones wrote: > > On Wed, Feb 28, 2024 at 05:01:22PM -0800, Atish Patra wrote: > > 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 failur= e. > > I don't know enough about the perf subsystem to know if there may be > a concern that resources are temporarily unavailable. If so, then this Do you mean the hardware resources unavailable because the host is using it= ? > patch would make it possible for a guest to do the exact same thing, > but sometimes succeed and sometimes get SBI_ERR_NOT_SUPPORTED. > sbi_pmu_counter_config_matching doesn't currently have any error types > specified that say "unsupported at the moment, maybe try again", which > would be more appropriate in that case. I do see > perf_event_create_kernel_counter() can return ENOMEM when memory isn't > available, but if the kernel isn't able to allocate a small amount of > memory, then we're in bigger trouble anyway, so the concern would be > if there are perf resource pools which may temporarily be exhausted at > the time the guest makes this request. > For other cases, this patch ensures that guests continue to run without fai= lure which allows the user in the guest to try again if this fails due to a temp= orary resource availability. > One comment below. > > > > > Fixes: 0cb74b65d2e5 ("RISC-V: KVM: Implement perf support without sampl= ing") > > 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 e= idx, 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_vcp= u *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); > > @@ -513,8 +515,10 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vc= pu *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_pm= u.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 *v= cpu, 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 > > Period after guest > > > > + * operation can continue without profiling. Forward the > > The operation > Fixed the above two. > > + * 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 > > > > Thanks, > drew -- Regards, Atish