From patchwork Mon Dec 3 23:34:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10710895 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A19D13BF for ; Mon, 3 Dec 2018 23:35:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4986029267 for ; Mon, 3 Dec 2018 23:35:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C20B2B212; Mon, 3 Dec 2018 23:35:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CF6229267 for ; Mon, 3 Dec 2018 23:35:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 456C56B6BAD; Mon, 3 Dec 2018 18:35:57 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3E02E6B6BAE; Mon, 3 Dec 2018 18:35:57 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25A856B6BAF; Mon, 3 Dec 2018 18:35:57 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id EB9CF6B6BAD for ; Mon, 3 Dec 2018 18:35:56 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id z68so14924891qkb.14 for ; Mon, 03 Dec 2018 15:35:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4tVgCUBHBNQMjCO6jTp3guECjaVmciwmYP+Klg4CL4Y=; b=eGKCFw2DwRr1EzKJyHsbynIUKZbSw6UVG411G4THhPgLGObDF3hoAchr7UJBvFrEF6 SE3P2SZaoX00GLz+f799SdDwZ0mrtESk1VJpG08mhq3L6inFSFjmttfAs1S6LFYu2p9u qEkKwuztZq1hm2mU4EibXgI/R+zh6HSCUyyw3VeVE+kGf5ze8jXX1Bu0CsG8PDYPGf2R au5LTsWhjW2Ftxdg5AXeU9HdSzdIymxPCLfv7kcpfj3cAZByAYrfzf1iGk/1VhtvkqgY oEcw4Ucsnc4AeIOxUOcxiGf8G9EtM/DGs10Pp9MTWe4nAIHVE2VmWByrS968pH3G/VNe CUyQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWY7LPlUhe3dLhn3imhKpghtnxraRiPRqocrR0lqfSX3EQN3ASGS JKchnJZLl4ZmNKIwmzE/6q4b7u0VUvXNuHSwZHRvIzPVV4nnnviFKO/9u57P1CwZeZouDDj1pAU oyC3ejXxb/U77Fts3ksW3fBRMf+pFPPKAYV35scD/5lX4nQdHVGYZF0A5EU3pCQ30jA== X-Received: by 2002:a0c:8b64:: with SMTP id d36mr17367525qvc.233.1543880156712; Mon, 03 Dec 2018 15:35:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/VWVzG/uKKA2N42hbyy29GFPEKOy78xQNb4uRdbR4hJk2UUqIFj2xBav7PXoRlkwmThagZK X-Received: by 2002:a0c:8b64:: with SMTP id d36mr17367490qvc.233.1543880156106; Mon, 03 Dec 2018 15:35:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543880156; cv=none; d=google.com; s=arc-20160816; b=KajVs1MdbYnZL0piWXAF3rFl3cHGn3rl93gR6/970a2Lmdk+O/V3c05WAFH68n0HOH 8K0xILXai+vDzUbT3D9hDTHLevLE5bmjVgBIIT4wN8MLHk3Sx8ZRWoou/Ldbt162KRfp ckczzbLeYNZnm0hHkfLfrphUZvXrOfCsaZ27yq14wLMR8SuxkFXAg/v8uQzYYlSVj7Xh z931M+SE5Fx1x2M/o1EYQI1mNuJmJU7Nck5vfm/I19t6FfGmGFulkL3Is3oMuTqa6HOn bMkdWQ14wck6nOotAfjZnfFGj2uvzsHMh+b5BuykMxrNpEcFZwi6WzeqXP1nP9lf6sSS axBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=4tVgCUBHBNQMjCO6jTp3guECjaVmciwmYP+Klg4CL4Y=; b=Hk1mUhGBazJkJdOqm929OecxbJTDaPm/9uWOPvicrJoQceoEA7WWr3uQcmP6nyLsDK DYSJcjlorC2iZRnlokWn6m+00/j02YB8srZKSxspE8wIUSOBFyzpiUhFrm2iLre8iIZG yUBw2EMajc0SOm0d9OXmY2PpzfnJpNFEynFQusu2/UbDiVAMyDcT/XcG0JC+WbFDVzEG Hi+VH9C9ZkY8m/GMn+QItG6+c4AQDDJPqOQIiDRvogiIQSmmzVHetaj1xD/F4Y+q0qZC Yiewgr+SScfckGBZId2RAaGkQr2oj5DCUtuFe1hQzW4eSqsyhvCMhpxERVDJ9XUqBw6x iAeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id u27si7805757qtb.176.2018.12.03.15.35.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 15:35:56 -0800 (PST) Received-SPF: pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0EF973082193; Mon, 3 Dec 2018 23:35:55 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-120-188.rdu2.redhat.com [10.10.120.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9833600C7; Mon, 3 Dec 2018 23:35:51 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org Cc: Andrew Morton , linux-kernel@vger.kernel.org, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , "Rafael J . Wysocki" , Ross Zwisler , Dan Williams , Dave Hansen , Haggai Eran , Balbir Singh , "Aneesh Kumar K . V" , Benjamin Herrenschmidt , Felix Kuehling , Philip Yang , =?utf-8?q?Christian_K=C3=B6nig?= , Paul Blinzer , Logan Gunthorpe , John Hubbard , Ralph Campbell , Michal Hocko , Jonathan Cameron , Mark Hairgrove , Vivek Kini , Mel Gorman , Dave Airlie , Ben Skeggs , Andrea Arcangeli Subject: [RFC PATCH 04/14] mm/hms: add initiator to heterogeneous memory system infrastructure Date: Mon, 3 Dec 2018 18:34:59 -0500 Message-Id: <20181203233509.20671-5-jglisse@redhat.com> In-Reply-To: <20181203233509.20671-1-jglisse@redhat.com> References: <20181203233509.20671-1-jglisse@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 03 Dec 2018 23:35:55 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Jérôme Glisse An initiator is anything that can initiate memory access, either a CPU or a device. Here CPUs and devices are treated as equals. See HMS Documentation/vm/hms.txt for further detail.. Signed-off-by: Jérôme Glisse Cc: Rafael J. Wysocki Cc: Ross Zwisler Cc: Dan Williams Cc: Dave Hansen Cc: Haggai Eran Cc: Balbir Singh Cc: Aneesh Kumar K.V Cc: Benjamin Herrenschmidt Cc: Felix Kuehling Cc: Philip Yang Cc: Christian König Cc: Paul Blinzer Cc: Logan Gunthorpe Cc: John Hubbard Cc: Ralph Campbell Cc: Michal Hocko Cc: Jonathan Cameron Cc: Mark Hairgrove Cc: Vivek Kini Cc: Mel Gorman Cc: Dave Airlie Cc: Ben Skeggs Cc: Andrea Arcangeli --- drivers/base/Makefile | 2 +- drivers/base/hms-initiator.c | 141 +++++++++++++++++++++++++++++++++++ include/linux/hms.h | 15 ++++ 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 drivers/base/hms-initiator.c diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 8e8092145f18..6a1b5ab667bd 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -12,7 +12,7 @@ obj-y += power/ obj-$(CONFIG_ISA_BUS_API) += isa.o obj-y += firmware_loader/ obj-$(CONFIG_NUMA) += node.o -obj-$(CONFIG_HMS) += hms.o hms-target.o +obj-$(CONFIG_HMS) += hms.o hms-target.o hms-initiator.o obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o ifeq ($(CONFIG_SYSFS),y) obj-$(CONFIG_MODULES) += module.o diff --git a/drivers/base/hms-initiator.c b/drivers/base/hms-initiator.c new file mode 100644 index 000000000000..08aa519427d6 --- /dev/null +++ b/drivers/base/hms-initiator.c @@ -0,0 +1,141 @@ +/* + * Copyright 2018 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Authors: + * Jérôme Glisse + */ +/* Heterogeneous memory system (HMS) see Documentation/vm/hms.rst */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static inline struct hms_initiator *hms_object_to_initiator(struct hms_object *object) +{ + if (object == NULL) + return NULL; + + if (object->type != HMS_INITIATOR) + return NULL; + return container_of(object, struct hms_initiator, object); +} + +static inline struct hms_initiator *device_to_hms_initiator(struct device *device) +{ + if (device == NULL) + return NULL; + + return hms_object_to_initiator(to_hms_object(device)); +} + +struct hms_initiator *hms_initiator_find_locked(unsigned uid) +{ + struct hms_object *object = hms_object_find_locked(uid); + struct hms_initiator *initiator; + + initiator = hms_object_to_initiator(object); + if (initiator) + return initiator; + hms_object_put(object); + return NULL; +} + +struct hms_initiator *hms_initiator_find(unsigned uid) +{ + struct hms_object *object = hms_object_find(uid); + struct hms_initiator *initiator; + + initiator = hms_object_to_initiator(object); + if (initiator) + return initiator; + hms_object_put(object); + return NULL; +} + +static void hms_initiator_release(struct device *device) +{ + struct hms_initiator *initiator = device_to_hms_initiator(device); + + hms_object_release(&initiator->object); + kfree(initiator); +} + +static ssize_t hms_initiator_show_uid(struct device *device, + struct device_attribute *attr, + char *buf) +{ + struct hms_initiator *initiator = device_to_hms_initiator(device); + + if (initiator == NULL) + return -EINVAL; + + return sprintf(buf, "%d\n", initiator->object.uid); +} + +static DEVICE_ATTR(uid, 0444, hms_initiator_show_uid, NULL); + +static struct attribute *hms_initiator_attrs[] = { + &dev_attr_uid.attr, + NULL +}; + +static struct attribute_group hms_initiator_attr_group = { + .attrs = hms_initiator_attrs, +}; + +static const struct attribute_group *hms_initiator_attr_groups[] = { + &hms_initiator_attr_group, + NULL, +}; + +void hms_initiator_register(struct hms_initiator **initiatorp, + struct device *parent, int nid, + unsigned version) +{ + struct hms_initiator *initiator; + + *initiatorp = NULL; + initiator = kzalloc(sizeof(*initiator), GFP_KERNEL); + if (initiator == NULL) + return; + + initiator->nid = nid; + + if (hms_object_init(&initiator->object, parent, HMS_INITIATOR, version, + hms_initiator_release, hms_initiator_attr_groups)) + { + kfree(initiator); + initiator = NULL; + } + + *initiatorp = initiator; +} +EXPORT_SYMBOL(hms_initiator_register); + +void hms_initiator_unregister(struct hms_initiator **initiatorp) +{ + struct hms_initiator *initiator = *initiatorp; + + *initiatorp = NULL; + if (initiator == NULL) + return; + + hms_object_unregister(&initiator->object); +} +EXPORT_SYMBOL(hms_initiator_unregister); diff --git a/include/linux/hms.h b/include/linux/hms.h index 0568fdf6d479..7a2823493f63 100644 --- a/include/linux/hms.h +++ b/include/linux/hms.h @@ -67,6 +67,17 @@ struct hms_object *hms_object_find_locked(unsigned uid); struct hms_object *hms_object_find(unsigned uid); +struct hms_initiator { + struct hms_object object; + int nid; +}; + +void hms_initiator_register(struct hms_initiator **initiatorp, + struct device *parent, int nid, + unsigned version); +void hms_initiator_unregister(struct hms_initiator **initiatorp); + + struct hms_target { const struct hms_target_hbind *hbind; struct hms_object object; @@ -95,6 +106,10 @@ int hms_init(void); #else /* IS_ENABLED(CONFIG_HMS) */ +#define hms_initiator_register(initiatorp) +#define hms_initiator_unregister(initiatorp) + + #define hms_target_add_memory(target, size) #define hms_target_remove_memory(target, size) #define hms_target_register(targetp, nid, size)