From patchwork Sat Feb 17 10:59:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 202634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp336556dyc; Sat, 17 Feb 2024 06:04:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXRQhIgKE3GQd64uTquZ4qjIk5unDEaBOdDOayCpr5LajANfp1wiV1Wzce5nkxSQKSLZgLJCoIdbqsFfK2ykZ2qcf1SsA== X-Google-Smtp-Source: AGHT+IFjz0N2lw5cq0dcU6yi35etPWBakC9RnQDtQDq3dA+WdWIPFuLeQW3DlWK6JGlOAaACSj7n X-Received: by 2002:a05:6a21:3a44:b0:19f:c0d3:4604 with SMTP id zu4-20020a056a213a4400b0019fc0d34604mr8058671pzb.46.1708178694946; Sat, 17 Feb 2024 06:04:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708178694; cv=pass; d=google.com; s=arc-20160816; b=Nr0PYEQjf8zYrTjq261nkgJ88xNrIm4j7V02hgeTjQ7ZXcRU5il2fvcGywaTnwg59z f59XOUWQSOKm90sEJLlZzRf2/c4/yUpgoNiKD87NQsEfJFR3J9H3UxPs5LWGN//OAqSM rqNjcICfTGDg2x5k2y2iNRuJaGYcZGxtO4mw9p9FffNmgBWVwihqQwBP03klc3O6EjXb gLWbOf6+VrnXV3I5Z+WbvIGnTgFlDT2uH2hL1Sc6RJ180mB1gQ4t7P8BHwHmL/IH8suQ gG5JYUqpQf62hWnw3w5m/vpBISC2MS0NCWA/1X9FiEuQC0pzV9BdMnC44qupJdTB2KsB qBlA== 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=FuVs7w7psiYm3JbOf6KpBwEhtyPW9YkqGGni1RCFiac=; fh=tt9aLUCPtZBDntIGGgm0DfYgLXsZUYzWtYgxP3QUZ1A=; b=gzJylNdIxpJd3mn8+Z5wJhAsLGTjVeLwINVBkT3CB5s6inPcPozzDHhEeD0e1U4SB9 nrpWrLCez/M44l0HSS6s8Cii/Hhr15Rv33mjhVi54wclOVcs0UnQEpOyGz7qImkVHqiS 2r7xoJEUtl8ckJBX41dBOzXesHFWlbzwtiJGHPEsZBaO8gkEABAjKx/k94F9FKSaDIWW eMZgbXHKxnY4pbj3v4aS9mTqz6/fggMfvjMB2V7iukVw+G6U58F7PEaGsLjEIKCStxa1 ce9LaH+3KKsh29JeW5LrN/PL2A+Wr/LCZ90pQPUPgYwSBBQCpTcvTLLepdhaPpWog3Bf 523A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=H+MpTSB+; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69815-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69815-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z1-20020a63ac41000000b005ceef6e1c1csi1534955pgn.708.2024.02.17.06.04.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 06:04:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69815-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=H+MpTSB+; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69815-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69815-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 0B5DF2828A0 for ; Sat, 17 Feb 2024 10:59:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E19A86025F; Sat, 17 Feb 2024 10:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="H+MpTSB+" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 941A159B6C; Sat, 17 Feb 2024 10:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708167563; cv=none; b=iJbEN3xHJlwZHTY/CWgi50MhBnQsRmf70SkDiGe3N/ZJ1l4E1wyekyG21aom99LrzIkJ7iCjQPtIO/hNi95Au43ujVnITKvkBykwpeoRRVYjPMZOOxMFoks03bv9ivz+9alNaVhPyxjwcICDzr7uYCmUoHamVuuYaagQi40h3R0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708167563; c=relaxed/simple; bh=XF+WjLg4KIqsngigqVAPUzNcgTjwiRifxdEA0ayezwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AyJxdjDF+6rh2PUWKw0s7z0WMEPYjeKnlkXvTL++MUecfcJQH1aAyMX3UrgPfx1uNqR/WAjoRujnnQXoxouVlom1ZBhhaSaRq7cUqG11NRXmd1YtByGYDJq+/fGjHyBSyRBumFS60LaC1o9p81ZbZa7I9Yrhu5pSqng+fmIpHPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=H+MpTSB+; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708167561; x=1739703561; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XF+WjLg4KIqsngigqVAPUzNcgTjwiRifxdEA0ayezwg=; b=H+MpTSB+GsqBssNOGC8aQYTz+CJXwIXdmpFEWVwO5mhPP2PMpBlrL2Wj QrmtPbIPtiJSwlkZUELavPjaTbth9Fx2J6uoZC49B9/BLuk8Djp+3Sog9 w/WsyVmjY07/ir3wnjRtRlsvEC5/srBFfnW6yEr4kkCpv/9pwgEUVitaA EkRQYfZ5M+ClGgor4wR3Z/P65YBXNgo71tZIsy7M2wEIkH27E+utmGzRr Vk7xIfgcI3f7stLND9DtTWvQq6inn/ZBqR3+mgQdkWs1Cz2ipcZQeBdAI OonjokmdGz0zlmQLD+cbK57iQWjw8t0R/J2mAGTmRje92PnyEmB3HHFYh g==; X-IronPort-AV: E=McAfee;i="6600,9927,10986"; a="27746704" X-IronPort-AV: E=Sophos;i="6.06,166,1705392000"; d="scan'208";a="27746704" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2024 02:59:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,166,1705392000"; d="scan'208";a="4348712" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.3.209]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2024 02:59:18 -0800 From: "Fabio M. De Francesco" To: Peter Zijlstra , Dan Williams , linux-kernel@vger.kernel.org Cc: linux-cxl@vger.kernel.org, Ingo Molnar , Dave Jiang , Jonathan Cameron , Ira Weiny , "Fabio M. De Francesco" Subject: [PATCH 1/3 v5] cleanup: Add cond_guard() to conditional guards Date: Sat, 17 Feb 2024 11:59:02 +0100 Message-ID: <20240217105904.1912368-2-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217105904.1912368-1-fabio.maria.de.francesco@linux.intel.com> References: <20240217105904.1912368-1-fabio.maria.de.francesco@linux.intel.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: 1791155183228690686 X-GMAIL-MSGID: 1791155183228690686 Add cond_guard() macro to conditional guards. cond_guard() is a guard to be used with the conditional variants of locks, like down_read_trylock() or mutex_lock_interruptible(). It takes a statement (or statement-expression) that is passed as its second argument. That statement (or statement-expression) is executed if waiting for a lock is interrupted or if a _trylock() fails in case of contention. Usage example: cond_guard(mutex_intr, return -EINTR, &mutex); Consistent with other usage of _guard(), locks are unlocked at the exit of the scope where cond_guard() is called. This macro can be called multiple times in the same scope. Cc: Dave Jiang Cc: Peter Zijlstra Suggested-by: Dan Williams Suggested-by: Ira Weiny Suggested-by: Jonathan Cameron Signed-off-by: Fabio M. De Francesco Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang --- include/linux/cleanup.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index c2d09bc4f976..602afb85da34 100644 --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -134,6 +134,19 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ * an anonymous instance of the (guard) class, not recommended for * conditional locks. * + * cond_guard(name, fail, args...): + * a guard to be used with the conditional variants of locks, like + * down_read_trylock() or mutex_lock_interruptible(). 'fail' is a + * statement or statement-expression that is executed if waiting for a + * lock is interrupted or if a _trylock() fails in case of contention. + * + * Example: + * + * cond_guard(mutex_intr, return -EINTR, &mutex); + * + * This macro can be called multiple times in the same scope, for it + * declares unique instances of type 'name'. + * * scoped_guard (name, args...) { }: * similar to CLASS(name, scope)(args), except the variable (with the * explicit name 'scope') is declard in a for-loop such that its scope is @@ -165,6 +178,13 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ #define __guard_ptr(_name) class_##_name##_lock_ptr +#define __cond_guard(__unique, _name, _fail, args...) \ + CLASS(_name, __unique)(args); \ + if (!__guard_ptr(_name)(&__unique)) _fail; \ + else { } +#define cond_guard(_name, _fail, args...) \ + __cond_guard(__UNIQUE_ID(scope), _name, _fail, args) + #define scoped_guard(_name, args...) \ for (CLASS(_name, scope)(args), \ *done = NULL; __guard_ptr(_name)(&scope) && !done; done = (void *)1) From patchwork Sat Feb 17 10:59:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 202601 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp258777dyc; Sat, 17 Feb 2024 03:00:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUefFkx/lNgvWHKkBSJs+cZ8YQQbEUF3NDE2J3hufdSWUdKAQ7URgzwiEpuM515o4Hho08HHOOvDRgDQaWsf5dfNLqzug== X-Google-Smtp-Source: AGHT+IFSALX6z8CqdRVdqevN83aEGe6t3cdz9hDIWstkLChf9ahX7Ydi3e1gyHjwAlzGNIVsv/Sx X-Received: by 2002:a05:622a:1883:b0:42c:78a5:ded with SMTP id v3-20020a05622a188300b0042c78a50dedmr10586317qtc.40.1708167602348; Sat, 17 Feb 2024 03:00:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708167602; cv=pass; d=google.com; s=arc-20160816; b=tSNVfrXWSI9tsTgmMVznQEwzB6ITzGrBvCqCFXAEKjTGmzVBA7k8Cm093wZbv34Y12 EaOOTnCaISlYJt1iXVqpPkIZ1i48O/l7vAWdvqE/UvOEfDmWBTQUaVThNNuWQplkuWEr +W6tHUCgfElhpIMmNJvxnaYDNZvHcl4e785V2ZXPyq9pYt5xotoGI2uk52FA/MDwIey4 IhpOr1/mNOeyjnAtQAkNnMNQUW7dP4PkTuP/YYfMaCfYpp6R64jhYibs7gilA5f1aiGG 88WUW6C+LqJCdjOCaWK3JhwiGJcfiq08Y4U/71y0yDRRB3a9vCYq6P4q2/qFrn8qrRH5 0Xuw== 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=6S9dpH8I0WDM1RgLBrc+lNlx0l9Du1Zr3Sj+oPA0ohs=; fh=tt9aLUCPtZBDntIGGgm0DfYgLXsZUYzWtYgxP3QUZ1A=; b=0Kh+p9IuIdkvLgnKwmVr2VHZFlPvAOAXHEcdwxc78y5sHcFZld9kNtR91u764p5LX0 51k3d9QWi+J6vAsyF4rXwo+xR9wBkLkJnGLGF55xKHfcr5GioM5Qh3ehv/rA909gFYz+ tan5+e0IRsnyF6qSfubpDRMftMYgG7lXPYOds3/3H3+trV9WIKkQLNh81ehQ/me/eomY ki1MD2A/6We+yxFlOOSGX01+joMNJnAsD4/A1IWZRzXtcPMIXcbsfPUebHppLpWKDaSQ peheqijXY83bSqv1DFShl1zemho/KmKMmU4IL1svzF+gklYFPBJA7Fg/uFT8ai2J2wQi qO+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ei9bSHA5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69816-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69816-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j13-20020ac8404d000000b0042c4534b298si1658981qtl.263.2024.02.17.03.00.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 03:00:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69816-ouuuleilei=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=@intel.com header.s=Intel header.b=ei9bSHA5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69816-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69816-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 B072B1C214CB for ; Sat, 17 Feb 2024 11:00:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3900B59B62; Sat, 17 Feb 2024 10:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ei9bSHA5" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FC5B5EE78; Sat, 17 Feb 2024 10:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708167566; cv=none; b=pPZvrvH4/F9w5QxG4huKE4QH4PH3qLH9ON9GyfAqYoZtVB5DsSU7fBDtuHIkpta/zxmoB4BOjHdq+5TAQkoRwQsa0YPw9kTV1ZV3Z0JMHa/01VD0Tpz2ltNpwGEAGS3OoN5f7qen/4h3KnJ+tLmbkw9zM7WIT4mtAld2CSL4GJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708167566; c=relaxed/simple; bh=tReqAs6fZ7zrpLVpBj5aMUSuggIHwZZRptD6FzY8tlA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AigoqT3cYoeqZzX2YPn0JHMOd8Mjt25G1mYSX7/yaqfcdtuIu5PYJ2LEilQlSUlHZ8cQaJRe6UQK9WKLViOuDzH309+W9WJhH8acP8q8HMQi8/N0fO/oIU4xJSGOyXqnHA0HQk0ur8aL+gWVNKvGystjtSgHq+qr/Z6zV6T5yrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ei9bSHA5; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708167565; x=1739703565; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tReqAs6fZ7zrpLVpBj5aMUSuggIHwZZRptD6FzY8tlA=; b=ei9bSHA5SrZ//3K2d8100vpikATXFyYliYcfHnoxkfn2IFP3vOzM5YNk EOvwchIA1pimOsMGarVyJI8tIXvGrMm8yjbX36He+dHBhFQu+i6yB/NpU Z6GpcEWLGHourpLIwNMM1iaQLA4ZO1GK3WiC9xgpOjGe1dO/wRQ1rnbWK 3CzNZbQ+VEhMhVyIjw9Pgn+869+D8v38NHKF1gKX44Y8vcBHByDh1/sVC 8BFrKJdq3PqnbspDQ80CSOnYgjP/YUkZUv0ixWoGTxVuHIzZsGPr5+ROj nksGxW8iBfrByxIvlsWaS4Ut9r20CNupEhlSIRxpj8a46X5nyxOJUHzoz A==; X-IronPort-AV: E=McAfee;i="6600,9927,10986"; a="27746710" X-IronPort-AV: E=Sophos;i="6.06,166,1705392000"; d="scan'208";a="27746710" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2024 02:59:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,166,1705392000"; d="scan'208";a="4348726" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.3.209]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2024 02:59:21 -0800 From: "Fabio M. De Francesco" To: Peter Zijlstra , Dan Williams , linux-kernel@vger.kernel.org Cc: linux-cxl@vger.kernel.org, Ingo Molnar , Dave Jiang , Jonathan Cameron , Ira Weiny , "Fabio M. De Francesco" Subject: [PATCH 2/3 v5] cxl/region: Use cond_guard() in show_targetN() Date: Sat, 17 Feb 2024 11:59:03 +0100 Message-ID: <20240217105904.1912368-3-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217105904.1912368-1-fabio.maria.de.francesco@linux.intel.com> References: <20240217105904.1912368-1-fabio.maria.de.francesco@linux.intel.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: 1791143551666168588 X-GMAIL-MSGID: 1791143551666168588 Use cond_guard() in show_target() to not open code an up_read() in an 'out' block. If the down_read_interruptible() fails, the statement passed to the second argument of cond_guard() returns -EINTR. Cc: Peter Zijlstra Suggested-by: Dan Williams Suggested-by: Ira Weiny Reviewed-by: Dave Jiang Reviewed-by: Ira Weiny Reviewed-by: Jonathan Cameron Signed-off-by: Fabio M. De Francesco --- drivers/cxl/core/region.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index ce0e2d82bb2b..704102f75c14 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -666,28 +666,20 @@ static size_t show_targetN(struct cxl_region *cxlr, char *buf, int pos) { struct cxl_region_params *p = &cxlr->params; struct cxl_endpoint_decoder *cxled; - int rc; - rc = down_read_interruptible(&cxl_region_rwsem); - if (rc) - return rc; + cond_guard(rwsem_read_intr, return -EINTR, &cxl_region_rwsem); if (pos >= p->interleave_ways) { dev_dbg(&cxlr->dev, "position %d out of range %d\n", pos, p->interleave_ways); - rc = -ENXIO; - goto out; + return -ENXIO; } cxled = p->targets[pos]; if (!cxled) - rc = sysfs_emit(buf, "\n"); - else - rc = sysfs_emit(buf, "%s\n", dev_name(&cxled->cxld.dev)); -out: - up_read(&cxl_region_rwsem); + return sysfs_emit(buf, "\n"); - return rc; + return sysfs_emit(buf, "%s\n", dev_name(&cxled->cxld.dev)); } static int match_free_decoder(struct device *dev, void *data) From patchwork Sat Feb 17 10:59:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 202607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp288618dyc; Sat, 17 Feb 2024 04:16:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUnT5gPBPoL0+ZhPrjDLJ532wmynQuTwAH29Hiyux03yzJ7rsh8BkrqJV3LWiUQZ3apIOJxylJsaKN7bRvyMjF1EAaUgg== X-Google-Smtp-Source: AGHT+IF9LmYPauzJYxn5liG/yjPfR7tkatFVo2MlfDu1LFb1UQf2h5M0Ea1huagODN4a+QdJxjrI X-Received: by 2002:a17:906:ce2b:b0:a3c:1603:7bc6 with SMTP id sd11-20020a170906ce2b00b00a3c16037bc6mr7833415ejb.36.1708172186070; Sat, 17 Feb 2024 04:16:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708172186; cv=pass; d=google.com; s=arc-20160816; b=FmySLwDUPC6EbggNRxdJOxk4yBtQG41IGzi5Mc12LY2sRL34VtTfvAV+Z5YyT8neiu 349zpjN5Hc33FO61+aajLBCQqMdVPjLv39iMm9FWedq0TIBzrqpdpmURguezJmgcy2hA gqfr9kpO9UPzUxr7gb/h79CgvXNcjDAfv+oNPfWq5uRa1ZExi0hx6J2uXalDKdjuT6ju wAHp2s9LHaTTsIblT5WSyUp/zqxuoIScP28N7FWj1Yijdtn2IJQorqWkQE983ZPq76Dh jZasols+kSUoZr823m6Fn65WMGANZ/egWJOyQm8AMNs/durHo2YOfvuPmaUHeL6yW0Kr CYLQ== 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=yQtscQC6zHwFuLcSAS0b/fdeEXmrpIJYMAON5RzEOy0=; fh=tt9aLUCPtZBDntIGGgm0DfYgLXsZUYzWtYgxP3QUZ1A=; b=VObFIVMUxIbkge9Pu5THErD+yOb4Od4SHjIamejqXVmgXSZes3A0AC1+eao+7gpWwb MfaYtq3LWlFGnVikfH88dSwh4zEXZNNPpMi7LJTCn839RuRje+jy0gLQB7LWaK97cVib Q5a9bLolJz2sGJUq7sJ409aOIUiVFR7zFuEzoa4Fdon+SZTSu9Ps7jOYpBK9YSDeVOCI EW9KgiM4pVjQFx4EGfRsuxprOptmWRzc95bioLs1O7clAmU3OVxHmmcrOGK+HOxjK3Qf 1t4ygZYkwskHaC3T33cWUXpV/uthpUx6rhdRKcBF5HXX2asAKXYWa1cVTP0u93l+5DuG SUEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XVlyEtFs; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69817-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id pw2-20020a17090720a200b00a3ce9c3587asi878325ejb.430.2024.02.17.04.16.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 04:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XVlyEtFs; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69817-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id BA84A1F22454 for ; Sat, 17 Feb 2024 11:00:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3915D60DEB; Sat, 17 Feb 2024 10:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XVlyEtFs" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF7BC60BBA; Sat, 17 Feb 2024 10:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708167570; cv=none; b=XI1DVRfoU9nkW0QReMmctT+U57FxtvM/sLtQUTg+nx+hTQNa4vrGDARsAmUKCcS+uYpmuE4E07YyjsWIZEmPy1s0QfulNJrW/DPyuO7D/47DSMjPj2nEbP5e34/sRIHOr9Ca0SXnTrzZCNkZ8juPDW3k2vGLNUW1cw2rsJNeO6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708167570; c=relaxed/simple; bh=Rg9lLhRXKxcDqABXuFQf8jwhkLJkiGL2KthCj4b7KB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aP593LR5z1vEDAcPEOsPokPXC6HcuhMff8pFFl377rNCBRfqltOZhIpuFuwmvjxdZJVKR1PstblBv0EFYmUEjvsNvI1oTCZIw8xHIXPSfKMUNxkcko9yqtLU5xeJHZPbFD1Z8or/QTyEjqv2iWftiT5zsA/N/GS7zdfbwrRcjR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XVlyEtFs; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708167569; x=1739703569; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rg9lLhRXKxcDqABXuFQf8jwhkLJkiGL2KthCj4b7KB8=; b=XVlyEtFsdA8o+E4MI0HYNcLutkco/64tCA6bLq7ZxqRY0zZcd7m4UKc7 EGMaZhuy8qAOnGO6MBVcLfPtmpT3fik3HqrX0qWA9El/FhP3DCORtsjIX yNMe3er52pPvqeKY9fWP8nPntnLDZ+IEBsKM4T+z7q6cctEvUSbTjkQJ3 i9CeDN4Udy9/mLBJKkah+G9caSCgBTTOUb8VeQUqzY0VXlpWKYKX11EEz pWULYGvimmy+NivjuTrnXtLzgFqHBrasXDiQLMvTn0LYwFBK7BuaqX1YN ojGiZK/oZZS1ne1bzbhgAlPxYeQhGvsGjgVCRSFwMmN5K1aHagESWo3Oj g==; X-IronPort-AV: E=McAfee;i="6600,9927,10986"; a="27746715" X-IronPort-AV: E=Sophos;i="6.06,166,1705392000"; d="scan'208";a="27746715" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2024 02:59:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,166,1705392000"; d="scan'208";a="4348739" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.3.209]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2024 02:59:25 -0800 From: "Fabio M. De Francesco" To: Peter Zijlstra , Dan Williams , linux-kernel@vger.kernel.org Cc: linux-cxl@vger.kernel.org, Ingo Molnar , Dave Jiang , Jonathan Cameron , Ira Weiny , "Fabio M. De Francesco" Subject: [PATCH 3/3 v5] cxl/memdev: Use cond_guard() in cxl_inject_poison() Date: Sat, 17 Feb 2024 11:59:04 +0100 Message-ID: <20240217105904.1912368-4-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217105904.1912368-1-fabio.maria.de.francesco@linux.intel.com> References: <20240217105904.1912368-1-fabio.maria.de.francesco@linux.intel.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: 1791148357852221494 X-GMAIL-MSGID: 1791148357852221494 Use cond_guard() in cxl_inject_poison() to not open code two up_write() in an 'out' block. If the down_read_interruptible() fail, the statements passed as the second argument of cond_guard() return -EINTR. Cc: Dave Jiang Cc: Jonathan Cameron Cc: Peter Zijlstra Suggested-by: Dan Williams Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang --- drivers/cxl/core/memdev.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index dae8802ecdb0..bd97eea65bb0 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -331,19 +331,13 @@ int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa) if (!IS_ENABLED(CONFIG_DEBUG_FS)) return 0; - rc = down_read_interruptible(&cxl_region_rwsem); - if (rc) - return rc; + cond_guard(rwsem_read_intr, return -EINTR, &cxl_region_rwsem); - rc = down_read_interruptible(&cxl_dpa_rwsem); - if (rc) { - up_read(&cxl_region_rwsem); - return rc; - } + cond_guard(rwsem_read_intr, return -EINTR, &cxl_dpa_rwsem); rc = cxl_validate_poison_dpa(cxlmd, dpa); if (rc) - goto out; + return rc; inject.address = cpu_to_le64(dpa); mbox_cmd = (struct cxl_mbox_cmd) { @@ -353,7 +347,7 @@ int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa) }; rc = cxl_internal_send_cmd(mds, &mbox_cmd); if (rc) - goto out; + return rc; cxlr = cxl_dpa_to_region(cxlmd, dpa); if (cxlr) @@ -366,11 +360,8 @@ int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa) .length = cpu_to_le32(1), }; trace_cxl_poison(cxlmd, cxlr, &record, 0, 0, CXL_POISON_TRACE_INJECT); -out: - up_read(&cxl_dpa_rwsem); - up_read(&cxl_region_rwsem); - return rc; + return 0; } EXPORT_SYMBOL_NS_GPL(cxl_inject_poison, CXL);