Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp418274rwb; Wed, 7 Dec 2022 20:38:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5nBZz3FfiS6EZLoCTLJGEg/u/299MQSQizCKXCayPoVVZN8uJX7/foozyNAmii28bRdvW4 X-Received: by 2002:a62:be16:0:b0:56b:676e:1815 with SMTP id l22-20020a62be16000000b0056b676e1815mr77713723pff.66.1670474315688; Wed, 07 Dec 2022 20:38:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670474315; cv=none; d=google.com; s=arc-20160816; b=FcCex2i8SN+w4q5XsSzOSK0AyLpzroNaroCOEaygieZouWPO/e8VvRziG+k7wX38sf T7CYpO9LKxZ0dKNPOJ91XvPFvElJBmkkR7h7GgZ/q2gMAlWrwNg3KLo93ZlIuoU3WqrH 9VRF0SjCG64+1smnCPELurqYTOyTLA1KAvNlIwz2UbMp4Js1guGMZWMP2WIuDCMPr9E4 ZZbeo3EsrfbWv4jBhnRw4m21i3nfV/+O+9vyQDR95nhsjCRGE94gbWcJqwzngCmZv8fi fsXZxucBeDofLdhsuR+2aAd4k8ozWR+tfRAaM3Ve7JfTvn6Wnoi1EGgan2L/w0p71YgD adbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7TByVMjeZWccwwsyCvk66teDJQUpmk5XX4C8QHTXg0Q=; b=DdTMQH+JkVEAQXfmOZoOgAbFXZUCYpEGl5PxcYeKenwW6Fe4q7a36LHviAT03XgKPh GFjqd1ZDqsckHJvlZhniHbHQwzh6OM6lJgYdeNv+lahU8T3Vd3mxT22dDP1001dDTipA DezG2LGXKsGkeEBoRfj7FmJcviGd0nWTXycZ7n//ror+pA/JE8exBK0+kMB+NkPI/zAw XfUmslsSjwFQ3KHnD4s3pkAVHCE/TC7BTQMfG3PuiX7p0jqH46HtoJ/CtOTx5lwdkMxQ THbXwyoF7WxGjLBArFR18SP9AgOvlpfGjUvkj/uP3c3pmCYxgJSpvbwG8pJHY41e2Fz1 kNzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SxQ4pHJz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l10-20020a170903244a00b001893b7f5ed7si25583392pls.205.2022.12.07.20.38.26; Wed, 07 Dec 2022 20:38:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SxQ4pHJz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbiLHDrl (ORCPT + 74 others); Wed, 7 Dec 2022 22:47:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbiLHDrj (ORCPT ); Wed, 7 Dec 2022 22:47:39 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7839BF48; Wed, 7 Dec 2022 19:47:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670471257; x=1702007257; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=rK8J3bc+OBp75ihGNvVIlZln4+9cNadZcCz8MTxE/l8=; b=SxQ4pHJzd+k6cxLrsSejRzdgQbIvBnH6ssdDOp58pkdJtCr8FSYo+0iq Wlf9mAEuPZt4l5KHuaY1jTUgZoXIGsFVpRAL/QLMeJ+pekACtGD06ui4i IP6UqUZ1Hh9YDdAoXyIindAa7ks2I6uyedS/y3Yw53WXsINU3pkRTbUH5 KqA4bTCfghLfoPyoH6Php0X68kAG7XoxV1iZmzJE8eaTra3LIe6Gt9gni g7tIUMZilLanxB/JWsiNW8ujEhI0dQD55MpQpQ1g6Zv02CF2KozMfaqze dNYzWfKkBg0NH1+nDx2HaiVNSieGDnpji7BMc4L8o+Z2DzwA2j++jCgn7 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10554"; a="296759120" X-IronPort-AV: E=Sophos;i="5.96,226,1665471600"; d="scan'208";a="296759120" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2022 19:47:37 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10554"; a="789143584" X-IronPort-AV: E=Sophos;i="5.96,226,1665471600"; d="scan'208";a="789143584" Received: from aschofie-mobl2.amr.corp.intel.com (HELO aschofie-mobl2) ([10.212.198.95]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2022 19:47:36 -0800 Date: Wed, 7 Dec 2022 19:47:35 -0800 From: Alison Schofield To: Dan Williams Cc: Ira Weiny , Vishal Verma , Dave Jiang , Ben Widawsky , Steven Rostedt , Ingo Molnar , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/6] cxl/mbox: Add GET_POISON_LIST mailbox command Message-ID: References: <46c7c7339224744fce424b196da3e5566effec17.1668115235.git.alison.schofield@intel.com> <638ffd5eaa3a7_c95729426@dwillia2-mobl3.amr.corp.intel.com.notmuch> <6391082ed3374_3cbe02947d@dwillia2-xfh.jf.intel.com.notmuch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6391082ed3374_3cbe02947d@dwillia2-xfh.jf.intel.com.notmuch> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 07, 2022 at 01:39:58PM -0800, Dan Williams wrote: > Alison Schofield wrote: > > On Tue, Dec 06, 2022 at 06:41:34PM -0800, Dan Williams wrote: > > > alison.schofield@ wrote: > [..] > > > > +int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, > > > > + struct cxl_region *cxlr) > > > > +{ > > > > + struct cxl_dev_state *cxlds = cxlmd->cxlds; > > > > + const char *memdev_name = dev_name(&cxlmd->dev); > > > > + const char *pcidev_name = dev_name(cxlds->dev); > > > > + struct cxl_mbox_poison_payload_out *po; > > > > + struct cxl_mbox_poison_payload_in pi; > > > > + int nr_records = 0; > > > > + int rc; > > > > + > > > > + po = kvmalloc(cxlds->payload_size, GFP_KERNEL); > > > > + if (!po) > > > > + return -ENOMEM; > > > > + > > > > + pi.offset = cpu_to_le64(offset); > > > > + pi.length = cpu_to_le64(len); > > > > + > > > > + rc = mutex_lock_interruptible(&cxlds->poison_list_mutex); > > > > > > So I do not know what this mutex is protecting if there is an allocation > > > per cxl_mem_get_poison() invocation. Although I suspect that's somewhat > > > wasteful. Just allocate one buffer at the beginning of time and then use > > > the lock to protect that buffer. > > > > Intent was a single lock on the device to protect the state of the > > poison list retrieval - do not allow > 1 reader. With > 1 reader > > software may not know if it retrieved the complete list. > > > > I'm not understanding about protecting a buffer, instead of protecting > > the state. Here I try to protect the state. > > Ah, sorry I read cxlds->poison_list_mutex and assumed it was serializing > access to the buffer, not a state machine. I do think it would be > worthwhile to make this a self contained structure with its own kdoc to > explain what is going on, something like: > OK thanks, it's getting through to me now. Will do ! > diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h > index ab138004f644..02697d1d951c 100644 > --- a/drivers/cxl/cxlmem.h > +++ b/drivers/cxl/cxlmem.h > @@ -193,6 +193,19 @@ struct cxl_endpoint_dvsec_info { > struct range dvsec_range[2]; > }; > > +/** > + * struct cxl_poison_state - summary > + * @payload: ... > + * @lock: ... > + * > + * A bit more description of why state needs to be held over successive > + * mbox commands... > + */ > +struct cxl_poison_state { > + void *payload; > + struct mutex lock; > +}; > + > /** > * struct cxl_dev_state - The driver device state > * > @@ -210,6 +223,7 @@ struct cxl_endpoint_dvsec_info { > * @lsa_size: Size of Label Storage Area > * (CXL 2.0 8.2.9.5.1.1 Identify Memory Device) > * @mbox_mutex: Mutex to synchronize mailbox access. > + * @poison: Poison list retrieval and tracing > * @firmware_version: Firmware version for the memory device. > * @enabled_cmds: Hardware commands found enabled in CEL. > * @exclusive_cmds: Commands that are kernel-internal only > @@ -244,6 +258,7 @@ struct cxl_dev_state { > size_t payload_size; > size_t lsa_size; > struct mutex mbox_mutex; /* Protects device mailbox and firmware */ > + struct cxl_poison_state poison; > char firmware_version[0x10]; > DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX); > DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX);