Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1706067rdb; Tue, 20 Feb 2024 04:51:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUtSmmdEM/AcYuwiT/dBzCCvU20LmQvPT179coZpI5ldVYwCCV9nGendb5mbytpm8Wj94Yp1Wma6yYpulPiD7mRiBH6AT7aER52s3y23A== X-Google-Smtp-Source: AGHT+IFw5BGvAZjcOweQhTgAVD7dkGAQld2c5+yc+MOifrpKfQd6k9PCAWJUGwpuV2xk8o7KQGOf X-Received: by 2002:a9d:6395:0:b0:6e2:f031:6956 with SMTP id w21-20020a9d6395000000b006e2f0316956mr16747195otk.30.1708433461399; Tue, 20 Feb 2024 04:51:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708433461; cv=pass; d=google.com; s=arc-20160816; b=Vx9CCk8NCinnSwsHj5MlsHGiy7xGaMQNGC4VAJPd0H9vWGHal4cqKpYQBfyoej5eND ZTvdDEL1AXFeoe5uMcSMD5cuRXVkK7XiRGK23PWIK+glmPFh1IFZ9sdz8GUDhlUaSwo3 HuYIe8GUSAlRj94SBRvwrynK/J8YET2mFxOG2glwHPgsvouXKMGkA1SH1nehXhYQZ4K0 iOqPoeeXWXXvRqS8Gz09qJkZuHstDoWUsJRiaM/kpWrz0C9KiqBzorkX8knGIwe6vfos MkMkpZwut+eWFjVbiQsFEYmd3zlFk0iD7HjR+U5OoZSgS3ihcVvJIHABNFjTwtTXjsgE ek3g== 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:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=1NUE54QJJn0oJJFoQjZVUw5YJZD930Si++My4UC+dy0=; fh=ehmdxMaNn1e64k03FAUDGH5ufF0BMazsqKtQWl0yC7M=; b=HJVjWghGwNQQ98BVrMiqjLE4JIbjBr6P1g5VVDeWvOuSfm3sYItH+6KVbvokGxSasu EaCR+yMegkenQyj9druXLJjdlqKyYugKz2k+NkQ2u6FQhKlt7cezzXqlSZ0ZZSMCy59T U6Nf9I67eBj+Yvqvk+QA+DAVmcbANe5UZ28zvuxI4rrtHdyHeBCCF3m89/FuMIT1//DK 1rHPu4hVkStagaNKaXHdhykXwTPDTbg/eY1LcLs9IZllhsHj4bSacuYWGsLFtHE4+yaG gMBB3EiC/wWCBMwNjAHGB99Ijr9QrHhzWpHrvf6hxFWbQM0Dmg8Bd8JlERB/zps0plzs fOkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-73032-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73032-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i7-20020a639d07000000b005dc5576a4fasi6180283pgd.770.2024.02.20.04.51.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 04:51:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73032-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-73032-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73032-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.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 45941285E4C for ; Tue, 20 Feb 2024 12:40:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDFDA6A03A; Tue, 20 Feb 2024 12:39:30 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 A4ADF657C4; Tue, 20 Feb 2024 12:39:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708432770; cv=none; b=XIibA1GNrdBHddIkWPxvAcFNz96bUfke10UkNkuAgWz4AQ8f0fzd+2HDih+r42gThGNnYGkWRXKep4UlQMoD30NYueCeaP+5vffGsD7UdPrx8VyEYobOCOzJZl8w8AeoxyeTsc2IceKyKtiXoo2S9J7dOIbWBBPsMKlJYWrIlDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708432770; c=relaxed/simple; bh=N34O3pudop+pKbhAnYHcokmzPaG4OYBsYjjNSgGGsCs=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qLTcvFU72qfRKmKKYkTzYJX3lsUoKAPi9GQWX5fAJRGVS2mzgmW4Uy8nRUJhq8R+dyVJce2XjvwK7FElPlEFryUdMGybZ/AGOTU/erccLaHLMbIx+MdII348mXdesgToK6fdJbkbh+P6Keg7bGbGkOIZtYR9CVynueMzZ1O3ltQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4TfJm54fYvz67l0C; Tue, 20 Feb 2024 20:35:49 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 3F78F14163B; Tue, 20 Feb 2024 20:39:24 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 20 Feb 2024 12:39:23 +0000 Date: Tue, 20 Feb 2024 12:39:22 +0000 From: Jonathan Cameron To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [RFC PATCH v6 06/12] memory: scrub: Add scrub subsystem driver supports configuring memory scrubs in the system Message-ID: <20240220123922.00007142@Huawei.com> In-Reply-To: <20240215111455.1462-7-shiju.jose@huawei.com> References: <20240215111455.1462-1-shiju.jose@huawei.com> <20240215111455.1462-7-shiju.jose@huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To lhrpeml500005.china.huawei.com (7.191.163.240) > From: Shiju Jose > > Add scrub driver supports configuring the memory scrubs in the system. > The scrub driver provides the interface for registering the scrub devices > and supports configuring memory scrubs in the system. > Driver exposes the sysfs scrub control attributes to the user in > /sys/class/scrub/scrubX/regionN/ > > Signed-off-by: Shiju Jose Hi Shiju, A few minor things inline. Given I reviewed this internally I don't have that much to add! Jonathan > --- > .../ABI/testing/sysfs-class-scrub-configure | 91 +++++ > drivers/memory/Kconfig | 1 + > drivers/memory/Makefile | 1 + > drivers/memory/scrub/Kconfig | 11 + > drivers/memory/scrub/Makefile | 6 + > drivers/memory/scrub/memory-scrub.c | 367 ++++++++++++++++++ > include/memory/memory-scrub.h | 78 ++++ > 7 files changed, 555 insertions(+) > create mode 100644 Documentation/ABI/testing/sysfs-class-scrub-configure > create mode 100644 drivers/memory/scrub/Kconfig > create mode 100644 drivers/memory/scrub/Makefile > create mode 100755 drivers/memory/scrub/memory-scrub.c > create mode 100755 include/memory/memory-scrub.h > > diff --git a/Documentation/ABI/testing/sysfs-class-scrub-configure b/Documentation/ABI/testing/sysfs-class-scrub-configure > new file mode 100644 > index 000000000000..d2d422b667cf > --- /dev/null > +++ b/Documentation/ABI/testing/sysfs-class-scrub-configure > +What: /sys/class/scrub/scrubX/regionN/rate_available > +Date: January 2024 > +KernelVersion: 6.8 > +Contact: linux-kernel@vger.kernel.org > +Description: > + (RO) Supported range for the scrub rate) > + by the scrubber for a memory region. > + The unit of the scrub rate vary depends on the scrub. Not good to have a unit that is dependent on scrub. We need to figure out how to either define that, or provide an interface to expose it to userspace and make it a userspace tool problem. > diff --git a/drivers/memory/scrub/memory-scrub.c b/drivers/memory/scrub/memory-scrub.c > new file mode 100755 > index 000000000000..a160b7a047e4 > --- /dev/null > +SCRUB_ATTR_RW(addr_base); > +SCRUB_ATTR_RW(addr_size); > +SCRUB_ATTR_RW(enable); > +SCRUB_ATTR_RW(enable_background_scrub); > +SCRUB_ATTR_RW(rate); > +SCRUB_ATTR_RO(rate_available); > + > +static struct attribute *scrub_attrs[] = { > + &dev_attr_addr_base.attr, > + &dev_attr_addr_size.attr, > + &dev_attr_enable.attr, > + &dev_attr_enable_background_scrub.attr, > + &dev_attr_rate.attr, > + &dev_attr_rate_available.attr, > + NULL, no comma > +}; > + > +static struct device * > +scrub_device_register(struct device *dev, const char *name, void *drvdata, > + const struct scrub_ops *ops, > + int region_id, > + struct attribute_group *attr_group) > +{ > + struct scrub_device *scrub_dev; > + struct device *hdev; > + int err; > + > + scrub_dev = kzalloc(sizeof(*scrub_dev), GFP_KERNEL); > + if (!scrub_dev) > + return ERR_PTR(-ENOMEM); > + hdev = &scrub_dev->dev; > + > + scrub_dev->id = ida_alloc(&scrub_ida, GFP_KERNEL); > + if (scrub_dev->id < 0) { > + kfree(scrub_dev); > + return ERR_PTR(-ENOMEM); > + } > + > + snprintf((char *)scrub_dev->region_name, SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH, > + "region%d", region_id); > + if (attr_group) { I'd like a comment on this. Not immediately obvious what this parameter is to me, or when we would and wouldn't have one. > + attr_group->name = (char *)scrub_dev->region_name; > + scrub_dev->groups[0] = attr_group; > + scrub_dev->region_id = region_id; > + } else { > + scrub_dev->group.name = (char *)scrub_dev->region_name; In both paths, drop out of if / else > + scrub_dev->group.attrs = scrub_attrs; > + scrub_dev->group.is_visible = scrub_attr_visible; > + scrub_dev->groups[0] = &scrub_dev->group; > + scrub_dev->ops = ops; > + scrub_dev->region_id = region_id; Set in both paths, so drop out of the if / else; > + } > + > + hdev->groups = scrub_dev->groups; > + hdev->class = &scrub_class; > + hdev->parent = dev; > + dev_set_drvdata(hdev, drvdata); > + dev_set_name(hdev, SCRUB_ID_FORMAT, scrub_dev->id); > + snprintf(scrub_dev->name, SCRUB_DEV_MAX_NAME_LENGTH, "%s", name); > + err = device_register(hdev); > + if (err) { > + put_device(hdev); > + return ERR_PTR(err); > + } > + > + return hdev; > +} > + > +static void devm_scrub_release(void *dev) > +{ > + struct device *hdev = dev; > + > + device_unregister(hdev); Trivial but local variable doesn't really add anything. deivce_unregister(dev); is pretty clear on types! > +} > diff --git a/include/memory/memory-scrub.h b/include/memory/memory-scrub.h > new file mode 100755 > index 000000000000..3d7054e98b9a > --- /dev/null > +++ b/include/memory/memory-scrub.h > @@ -0,0 +1,78 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Memory scrub controller driver support to configure > + * the controls of the memory scrub and enable. > + * > + * Copyright (c) 2023 HiSilicon Limited. > + */ > + > +#ifndef __MEMORY_SCRUB_H > +#define __MEMORY_SCRUB_H > + > +#include > + > +enum scrub_types { > + scrub_common, > + scrub_max, No comma on a terminating entry like this. > +};