From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BAC120F972 for ; Thu, 23 Jan 2025 14:16:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737641795; cv=none; b=Rj8Mqzw8YlDvG4+I4VGGImBZh9EF64WhfNH17nVkj6VPISJhEyILci5VD8N3ThszsGmnw+IpTHVlraAFBZC5Y/IFHy8GXztHDRvQkJw2X72VG1XGgxeGZ8uDbIrkFWkl7oZ80oj4gMfvzPFXbb6EpbVbs8LgJecTB3gNuuXJivE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737641795; c=relaxed/simple; bh=6V3W+o+MWoic0jA4thqpS40vCUdZ/uudiQaYYdeTdEo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=p4ZpPUT7XbKUJ7aI+7DpMRIPJdcfmd6x6Y8Z5HnV/BBg+hqJ9Tq2H1RSjzzbUrBelZcdxvV3UBRGBahPQcn2+FhnWuiLNKQ5KFIB8FJ059i4Zd2IKfzP15Ugn1TDPdHMlVCsGfn9ZY9iZF0oyj1KVsXWN8zZgf+fMi2zy3F4L+w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Vvlx3XyL; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Vvlx3XyL" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-385d7f19f20so467305f8f.1 for ; Thu, 23 Jan 2025 06:16:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1737641791; x=1738246591; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=QDz8608lNaW0P9BTT1X9DLek8Kcys+jnF/tb6a9Lcbw=; b=Vvlx3XyLK269fz/1nd7DHEn9lt1dWkSZnvM3xyPmFiKFF3X7dyXNsy6zu1opJhq7hC aDzl/gHg/lgksQ7mvGxoZtK1t64sNknbAsP2AKTTG0qLPQvwYo0mMfWfRGUWfMxznEAl agVvTe4A6e+RzelX9HSh3Z4N6LqWh11u5I0TllfBz+yxao2lU4djR1AFhjAVrqKPf70l ycH2feDrUvUqlXoAKSnCAHfjjSEyUANOkvsYkjSD03bdgkiCkq2tURFxWbFvoMBUdSei NpI4Z7cJqZEmT5ecg1EdCDgX4NisstLkbn/QYeQAh0Qe6CwOEnJBSOol0JlW/9lOgELI uFUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737641791; x=1738246591; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QDz8608lNaW0P9BTT1X9DLek8Kcys+jnF/tb6a9Lcbw=; b=XHxC3owiqst9Uh5jNAbdztR/svecmgNwvT1XplFCqrPNUof3V6v5allNP/qj7yFEBI 9a92eO7hrPzGA9ay+QO73weK5XPNNVvd7mLKmXCyo1iJbHZg4scO6jHG6l98dptYlSVK /M/kN6T3aOIYqHCUFJ6KDVMs0qKge5G/DoCtq/NnhShOPOhni5EOhjIQZ09ls5k89lHI WRuSRRlwQm483qnupT9LZNRrc35rgrwGR4M1o1NA0DTIHELRrNz9CVhPrJ2FYdc++QC4 BEDPMKXX0n0P0UA5/ksPXArjKkkdbPVy+8WzO8kFemIEUQEtyA1MTDyIj8wTzRBH+LEh 4uIQ== X-Forwarded-Encrypted: i=1; AJvYcCXcHgeblicCJaQgYQZXVonIaRipSbLaSm0jfgqsEQhcY2G2bimVq8xoejTRjCI46nYhG4BPebcGeB2gwA8=@vger.kernel.org X-Gm-Message-State: AOJu0YwOp30IsfyrSpAr5gY1D4TdyVKgU7donUfunyjk1YvXVno0y8T/ OSq2j/O0XxplOgCHN3cDuNEV3z4OLd9MGYCZWb8KUnwoKZhKr4XfxNG5MXjcFxE= X-Gm-Gg: ASbGncsmlWXqcaJwAump/BTO+Nfzal0mBJIwE5eXRaUGq5IHIqkn6QLcn6/G3aTBjCl swEAbQn8cdfVDA86kM7gNcIz6Zx3RsvXOguHzNjiSZCdjbc/8LRAyjXu7Khv5dkccZKyH6CLzbM HoL/Asf4tKz2wsb460kWu0w02wWYVh3ARV3tOH9sjX4yxbfVsg9ZjhOGW6ZkJdjvvxFHKs4qMCo mTVloLFOnR1r7mtjvSyWbn1BDYG94IgUClmRt9ClJgQequ+RzKsXzc1UM4LWnL8oKP3DIizXkFY G6vYK8k+ X-Google-Smtp-Source: AGHT+IEZ3PnxYGUvf8/rU964wji50OH+SsshrvGk6eo7bEmtZzJZRo7kuLNRZ25HdqIFvqguWQOL1A== X-Received: by 2002:a5d:4243:0:b0:386:2a3b:8aa with SMTP id ffacd0b85a97d-38bf57b3f56mr16813575f8f.37.1737641791528; Thu, 23 Jan 2025 06:16:31 -0800 (PST) Received: from [10.100.51.161] ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf3275595sm19543698f8f.67.2025.01.23.06.16.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 06:16:31 -0800 (PST) Message-ID: <4a9ca024-fc25-4fe0-94d5-65899b2cec6b@suse.com> Date: Thu, 23 Jan 2025 15:16:28 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 06/10] module: introduce MODULE_STATE_GONE To: Mike Rapoport Cc: x86@kernel.org, Andrew Morton , Andy Lutomirski , Anton Ivanov , Borislav Petkov , Brendan Higgins , Daniel Gomez , Daniel Thompson , Dave Hansen , David Gow , Douglas Anderson , Ingo Molnar , Jason Wessel , Jiri Kosina , Joe Lawrence , Johannes Berg , Josh Poimboeuf , "Kirill A. Shutemov" , Lorenzo Stoakes , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Miroslav Benes , "H. Peter Anvin" , Peter Zijlstra , Petr Mladek , Petr Pavlu , Rae Moar , Richard Weinberger , Sami Tolvanen , Shuah Khan , Song Liu , Steven Rostedt , Thomas Gleixner , kgdb-bugreport@lists.sourceforge.net, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-um@lists.infradead.org, live-patching@vger.kernel.org References: <20250121095739.986006-1-rppt@kernel.org> <20250121095739.986006-7-rppt@kernel.org> Content-Language: en-US From: Petr Pavlu In-Reply-To: <20250121095739.986006-7-rppt@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 1/21/25 10:57, Mike Rapoport wrote: > In order to use execmem's API for temporal remapping of the memory > allocated from ROX cache as writable, there is a need to distinguish > between the state when the module is being formed and the state when it is > deconstructed and freed so that when module_memory_free() is called from > error paths during module loading it could restore ROX mappings. > > Replace open coded checks for MODULE_STATE_UNFORMED with a helper > function module_is_formed() and add a new MODULE_STATE_GONE that will be > set when the module is deconstructed and freed. I don't fully follow why this case requires a new module state. My understanding it that the function load_module() has the necessary context that after calling layout_and_allocate(), the updated ROX mappings need to be restored. I would then expect the function to be appropriately able to unwind this operation in case of an error. It could be done by having a helper that walks the mappings and calls execmem_restore_rox(), or if you want to keep it in module_memory_free() as done in the patch #7 then a flag could be passed down to module_deallocate() -> free_mod_mem() -> module_memory_free()? It is at least good that MODULE_STATE_GONE is only set in free_module() past the sysfs teardown, so it never shows in /sys/module//initstate. Otherwise, this would require teaching kmod about this state as well. -- Thanks, Petr