From patchwork Thu Apr 27 00:08:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13225058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C92E9C7618E for ; Thu, 27 Apr 2023 00:49:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 655C16B0071; Wed, 26 Apr 2023 20:49:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62D336B0072; Wed, 26 Apr 2023 20:49:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51B976B0074; Wed, 26 Apr 2023 20:49:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 437076B0071 for ; Wed, 26 Apr 2023 20:49:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1498E8020B for ; Thu, 27 Apr 2023 00:49:37 +0000 (UTC) X-FDA: 80725337994.14.7997F9C Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf03.hostedemail.com (Postfix) with ESMTP id 0D5182000A for ; Thu, 27 Apr 2023 00:49:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=lFddECHU; spf=pass (imf03.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=none) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682556575; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=43eGY+TDyN1Z/nEUhZp/pkRJ381CTkYO9EwFJXyHijs=; b=x7rSWeq4+fLh2lRmaJD8wxQ0Jud1QDgsiIUIyNfFeEYsN0PkwDUZZNZKusPiEHbkxWb7nv 0uurn58qWCSI091ttEcD0dYErnG7y4VO/f1iyqBS+SkPv+Yvp6nTLYZ+DbrcBoa1uQylw1 XUurVrMLx+KQxYV6CzAdUAXfadph4xY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=lFddECHU; spf=pass (imf03.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com; dmarc=pass (policy=none) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682556575; a=rsa-sha256; cv=none; b=GFCHnJk6sbwiRb0Xg4wByKI07wzy4dARukphS7LWpNd8OoehwI3ir52YNgQu1HwGBdLDz5 Fomaw/5FMH0dFOHWw01C9Vf2fFKWoJUOYV7t17kos6KzVIV4DIzJtjtyp6vvgBPJhPPCby QBp+chJ9a456+UcYy6Ovn2soYEN26OE= Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33QGx63C014744; Thu, 27 Apr 2023 00:09:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-03-30; bh=43eGY+TDyN1Z/nEUhZp/pkRJ381CTkYO9EwFJXyHijs=; b=lFddECHUFaWe4SvxIWe74XuldZD3XhgVHok2PgKl2CS5V9ILX3LvwHV30JNs3cypkMZR 8uiAfjJTFIhtWlrJRlFDLbAorKgQgvIuVOLrLSEI6IxPSo58U7I0ugig8LUpDtroQYf0 qEQ1xL25lZRaIfxmaXWpRfGNpN5jYkV1m5iS+Qye7WwBzoSapoardIE7ZBZBnESy+/4m gSbsTmhPLiFOZ+wkOz++c0c0sgsqgkb4FrVZUnIxbqFMpcl7ubrUGjWlxLi5zPvEIXaS CguZa3wdyDWhJpmUoSLf4r4OI1kFIpshJwuSTa3CKlRl9yR0fibdnDQCo6NYgE9+jhUZ TA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q47fatmse-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:31 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33QMn2Cq007147; Thu, 27 Apr 2023 00:09:31 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q4618mpu2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Apr 2023 00:09:31 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33R0938w013888; Thu, 27 Apr 2023 00:09:30 GMT Received: from ca-qasparc-x86-2.us.oracle.com (ca-qasparc-x86-2.us.oracle.com [10.147.24.103]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3q4618mp42-19; Thu, 27 Apr 2023 00:09:30 +0000 From: Anthony Yznaga To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, rppt@kernel.org, akpm@linux-foundation.org, ebiederm@xmission.com, keescook@chromium.org, graf@amazon.com, jason.zeng@intel.com, lei.l.li@intel.com, steven.sistare@oracle.com, fam.zheng@bytedance.com, mgalaxy@akamai.com, kexec@lists.infradead.org Subject: [RFC v3 18/21] mm: PKRAM: allow preserved memory to be freed from userspace Date: Wed, 26 Apr 2023 17:08:54 -0700 Message-Id: <1682554137-13938-19-git-send-email-anthony.yznaga@oracle.com> X-Mailer: git-send-email 1.9.4 In-Reply-To: <1682554137-13938-1-git-send-email-anthony.yznaga@oracle.com> References: <1682554137-13938-1-git-send-email-anthony.yznaga@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-26_10,2023-04-26_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304270000 X-Proofpoint-ORIG-GUID: -W4-EPoCWhe2SX1_zknW2SnhXj4oiT4p X-Proofpoint-GUID: -W4-EPoCWhe2SX1_zknW2SnhXj4oiT4p X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0D5182000A X-Stat-Signature: 3kmz7kgmjuz3qb975m43xyrpc1hx8x8k X-HE-Tag: 1682556574-190716 X-HE-Meta: U2FsdGVkX18yG0jjZP9fu1GTIktCztRXmzbB5fJG+fod1yM6Qh3/vNHWjYdgzfxGUnBK3xg1frPuRRbAa1gJkEsguSPTM7s8gtJJlT+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version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: To free all space utilized for preserved memory, one can write 0 to /sys/kernel/pkram. This will destroy all PKRAM nodes that are not currently being read or written. Originally-by: Vladimir Davydov Signed-off-by: Anthony Yznaga --- mm/pkram.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/mm/pkram.c b/mm/pkram.c index 474fb6fc8355..d404e415f3cb 100644 --- a/mm/pkram.c +++ b/mm/pkram.c @@ -493,6 +493,32 @@ static void pkram_truncate_node(struct pkram_node *node) node->obj_pfn = 0; } +/* + * Free all nodes that are not under operation. + */ +static void pkram_truncate(void) +{ + struct page *page, *tmp; + struct pkram_node *node; + LIST_HEAD(dispose); + + mutex_lock(&pkram_mutex); + list_for_each_entry_safe(page, tmp, &pkram_nodes, lru) { + node = page_address(page); + if (!(node->flags & PKRAM_ACCMODE_MASK)) + list_move(&page->lru, &dispose); + } + mutex_unlock(&pkram_mutex); + + while (!list_empty(&dispose)) { + page = list_first_entry(&dispose, struct page, lru); + list_del(&page->lru); + node = page_address(page); + pkram_truncate_node(node); + pkram_free_page(node); + } +} + static void pkram_add_link(struct pkram_link *link, struct pkram_data_stream *pds) { __u64 link_pfn = page_to_pfn(virt_to_page(link)); @@ -1252,8 +1278,19 @@ static ssize_t show_pkram_sb_pfn(struct kobject *kobj, return sprintf(buf, "%lx\n", pfn); } +static ssize_t store_pkram_sb_pfn(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int val; + + if (kstrtoint(buf, 0, &val) || val) + return -EINVAL; + pkram_truncate(); + return count; +} + static struct kobj_attribute pkram_sb_pfn_attr = - __ATTR(pkram, 0444, show_pkram_sb_pfn, NULL); + __ATTR(pkram, 0644, show_pkram_sb_pfn, store_pkram_sb_pfn); static struct attribute *pkram_attrs[] = { &pkram_sb_pfn_attr.attr,