Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp186846rbe; Wed, 28 Feb 2024 17:07:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVsYbBhxCY36dtrXgLfs5FszysGhkFf4qgtxv9K/j902kMhatwqzii9UR9Py50TbX3RV0bo7cndj0h+psxUG/KQk1cFOTTYCl1M06oCkg== X-Google-Smtp-Source: AGHT+IH947lqb0xxsQlDreyBV5ZdsQiCUnHq0YIrHE/MFABRxxxITDcy2ZFwQjlDRFZhB2wuHKj5 X-Received: by 2002:a05:620a:29c1:b0:787:b833:7036 with SMTP id s1-20020a05620a29c100b00787b8337036mr735571qkp.6.1709168829559; Wed, 28 Feb 2024 17:07:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709168829; cv=pass; d=google.com; s=arc-20160816; b=UYICqKYDH87/8H9YtOtUYJFoX9g5GRfSxVqhcp1FwWuw0y5Eq05P7Tjbt8Ro1cbFU8 /ramqV5ltYqbEmn32BzwCtsO3OT+Eqw/XvihZIPPAGMxsxYtjNolOITyzmYY+KMG/6Bw 1Gq/lYXwAQqgXL8pWSUzMtPA6FHcHBbUArYrNL8l7A5XG5WueR0qzVkIyoXtzJsI/V/B Sk123SeSmwk4/wCFpTAk4blwdOVZYciMnLZp5EBEKToHtE//1iEZBhdVw12DcAfWSRj3 GSVmm5Qv/ww+HD/YRZBU1oU/UmlkF+oNdjwdO8OjXVU7fUA8BOS/OaqzKry2y0pWDk7e YRVQ== ARC-Message-Signature: i=2; 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=LL/IoSpoKvZJ2Khobth9w7yxft2CAXRQCGWgxGmHMSI=; b=XqUQrNBbf1liWNTwl5VNX+VGoz27B0VGk56VBMGetAe7eDF4isowTy0/uHeg2wsq7j OFqKYMtpo5BwNmiMaJs/aygjLMWuEYXwBzH2OPYLiCqsUhYY6qNPUrSTP7c9f3nCYamm koRMN8sHhsrkodR1ycfFm15oxYpE6BYmWLdivEo4O4VKJ0xFEDfhIB5mh0dhA5aMm4Nc KqraFxW3UBL5wkXiodPCU6BIUmYDMffFOZ8WPP1ANEXFXsHN9PJn7k5c1koWVEySZqWa rC9OxNCljI2uZwoPRwzJh11dEePBxWwo2HBLNTAh8Q4UZiJ+WfLPUiWlFpiQ0XpNP4Lm 1bAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=escQEYB1; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-85974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85974-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 bm35-20020a05620a19a300b00787400a8ce8si436524qkb.693.2024.02.28.17.07.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 17:07:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85974-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=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=escQEYB1; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-85974-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85974-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 0F8181C202F5 for ; Thu, 29 Feb 2024 01:07:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FBCB50A6C; Thu, 29 Feb 2024 01:01:57 +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="escQEYB1" Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 110C94D9E0 for ; Thu, 29 Feb 2024 01:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709168516; cv=none; b=BH3qFjeLiLFzqitTZXAchW5BW40VZIemurC0egs9EAgzFNxIYWNu8WWHTy+PMDYBeQQET8o6qlZLGPIUpxPvZ0foEZKwhQVm5p1z0/IDD/OsKHkS80prt6b0EQwiV71VYak60Xj3IU2VjRCCNmDX7vVxOpATRQuuEWMxprDM9aI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709168516; c=relaxed/simple; bh=1V+hd27rw6/WCAn1DleSGvGCcsHuYA/SEtOYZLS88jw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=af6jaIqIAFvgB964CssfSWd5FvzhC/BmD56k3xJHnrV2FezAWl1+E625FHq1tyZ+f5KS84WPX3126INyClG55SojX0uk5Y8cTg70xavnGsLn498F6gHjBUxvRr0WoaC1LI3g0O2dA7qXfYsgbyiWIlGXbNqEDzgX13eljoFcnQE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=escQEYB1; arc=none smtp.client-ip=209.85.214.176 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-pl1-f176.google.com with SMTP id d9443c01a7336-1dc3b4b9b62so3231215ad.1 for ; Wed, 28 Feb 2024 17:01:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709168514; x=1709773314; 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=escQEYB1Bt2ZRhOrHnHHGHTMTtiK2PT9goLugDyI1ImLJ6839ez8vfF79zcBaDAuuy My+9HvtTnsWQk0gpxxXSFDtSc5bOBjKvsBRJRnJd4VX8btBvfrc+wb1i5tzWvYaOZd/H 0j6xCFXVBt0K8iwclxQxrcqben9wzVEJ4+M59sqXTgW8OAclqB5YHrOXPL1t37Qd0WOr FQvm0inngPh/iJ3bpkHGUF/KN4NeQjq0TTY/d1RSGR3jdfkWdIoF/kwvKXmOotIYbrhb pimor46BVZ3KcfM4Fe/nXHOsop7MFpyQkELX3y+ySVPKmcLEi3SuYxgQnV64R7iYqPg/ pE9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709168514; x=1709773314; 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=gZrS3+5jUIKrmFQhdLbejuxY0ilEoiEczVzxxDLzhKryl9rDt4QGx0juZn4+2xEqFT 6e010MxlMsTJL6XNPFXcjW2gFYasWA7bRM3qriXi3V4rV+4C/1IE2cnOkFIgkbJA5svG SKv5FABRoPtyf5H74rGQD3wqGhHcg+cGYr4x8BSIPVAxCL+hdep43j+6KAtBqF1A7Jhl sCjhzJwE95Ra2XbH5K3N4apvobMwPGZGaSe9UwDS3woRwvec7UUAOn5rih8GlLh5ThAi T4k6Lfs39+NIE5zIkcC9CdeOxG9Xb6HFLzJXyN4uMNPiSUrX7hS7Zc/ynwLVb/gLcqav zmOg== X-Gm-Message-State: AOJu0Yxo4pt4U1AuW8UWUNe44Gi6oPyzxY+dIHTPO1oFxd0ctyDfHMD3 gc28+gaicRtG5KoIDo5qiQ39R17UBtYKpxtRI9Mn+AmW7MohMPine5vTRrLpeBrtCAexyrsOWqU X X-Received: by 2002:a17:903:32cd:b0:1db:edb8:35f6 with SMTP id i13-20020a17090332cd00b001dbedb835f6mr622961plr.5.1709168513907; Wed, 28 Feb 2024 17:01:53 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id j14-20020a170902da8e00b001dc8d6a9d40sm78043plx.144.2024.02.28.17.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 17:01:53 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Albert Ou , Alexandre Ghiti , Andrew Jones , Atish Patra , 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 Subject: [PATCH v4 07/15] RISC-V: KVM: No need to exit to the user space if perf event failed Date: Wed, 28 Feb 2024 17:01:22 -0800 Message-Id: <20240229010130.1380926-8-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240229010130.1380926-1-atishp@rivosinc.com> References: <20240229010130.1380926-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.34.1