linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Joshua Hudson <joshudson@gmail.com>, Al Viro <viro@zeniv.linux.org.uk>
Cc: Bagas Sanjaya <bagasdotme@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux IDE and libata <linux-ide@vger.kernel.org>,
	Hans de Goede <hdegoede@redhat.com>, Jens Axboe <axboe@kernel.dk>,
	Damien Le Moal <dlemoal@kernel.org>,
	OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Subject: Re: Cache coherency bug: stale reads on /dev/sda1
Date: Wed, 6 Sep 2023 09:42:27 +0200	[thread overview]
Message-ID: <9ee5affc-54b3-4b27-9311-4ed3bb73afc9@suse.de> (raw)
In-Reply-To: <CA+jjjYT1NgR79CuBso4O_C=jVKRG8GKbv8xu9aqPJFv1hOJ=3Q@mail.gmail.com>

On 8/27/23 20:33, Joshua Hudson wrote:
> On Sun, Aug 27, 2023 at 9:30 AM Al Viro <viro@zeniv.linux.org.uk> wrote:
>>
>> On Sun, Aug 27, 2023 at 07:39:03AM -0700, Joshua Hudson wrote:
>>> Offset 0x1C into the FAT filesystem is defined as "Count of hidden
>>> sectors preceding
>>> the partition that contains this FAT volume." It's been there since
>>> DOS 3.0. The Linux
>>> Kernel does not care what's in this field, but I have tools that have
>>> a hard time of it
>>> not being there. One example of a tool is BootDuet.
>>>
>>> The rationale is to reduce the number of tools that have to walk the
>>> partition table, the
>>> most obvious one being the boot sector itself which doesn't have room.
>>
>> ???
>>
>> That makes no sense whatsoever; "boot sector" here is the first sector
>> of _partition_, not that of the entire disk (that would be MBR).
>>
>> To quote the same wikipedia,
>> ----
>> A volume boot record (VBR) (also known as a volume boot sector,
>> a partition boot record or a partition boot sector) is a type of boot
>> sector introduced by the IBM Personal Computer. It may be found on a
>> partitioned data storage device, such as a hard disk, or an unpartitioned
>> device, such as a floppy disk, and contains machine code for bootstrapping
>> programs (usually, but not necessarily, operating systems) stored in other
>> parts of the device. On non-partitioned storage devices, it is the first
>> sector of the device. On partitioned devices, it is the first sector of
>> an individual partition on the device, with the first sector of the entire
>> device being a Master Boot Record (MBR) containing the partition table.
>> ----
>>
>> So your rationale doesn't work - you need to know where the partition is
>> just to read the sector that contains that field.  Or have access to
>> something that can be asked to read from partition, as opposed to the
>> entire disk (kernel, for example), but that something can usually be
>> asked where the hell does partition start.
> 
> The MBR doesn't look at the BPB. It looks at the first four bytes of the
> partition table entry, loads that sector (which is the VBR), and jumps to
> it. In the late 90s it became a thing to pass DL all the way through to
> enable booting from ZIP disks, but nothing else is passed from the MBR
> to the VBR. Thus, the BPB is in the VBR and describes the filesystem
> and knows its own offset (otherwise the disk would not boot).
> 
> https://github.com/FDOS/kernel/blob/132a0a9f94d23f13c90319bb0e0232a5f33164d8/boot/boot.asm#L203
> 
> Almost everybody depended on this exact behavior for dual booting. Each
> OS was defined in the boot menu as a path to a 512 byte file, which was
> that OS's boot sector. They don't access disk relative to their own position,
> but rather what their position should be.
> 
> So what I did: unmounted /boot/efi, started a virtual machine with /dev/sda
> as the disk, booted a different OS than the host OS, shut it down, and got
> very confused when changes to /boot/efi via the guest OS were not reflected
> in the host OS.
> 
>>
>> On anything with UEFI the first sector of the entire disk is likely to be
>> the "protective MBR" in the beginning of GPT.
>>
> 
> # dd if=/dev/sda bs=c skip=446 count=66 | hexdump -C
> 00000000  00 00 02 00 ee ff ff ff  01 00 00 00 af 88 e0 e8  |....îÿÿÿ....¯.àè|
> 00000010  80 20 21 00 06 df 13 0c  00 08 00 00 00 20 03 00  |. !..ß....... ..|
> 00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
> 00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
> 00000040  55 aa                                             |Uª|
> 00000042
> 
> I wouldn't be too sure of that. And yes, the second line corresponds
> exactly to the EFI partition's entry in GPT.

Weelll ... if you already know that there's something in the FAT 
documentation which isn't implemented in Linux, why are you surprised 
that things don't work if you modify it?
And if you know that tools are relying on that specific field, why not 
implement support for that feature in linux?

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew
Myers, Andrew McDonald, Martje Boudien Moerman


      reply	other threads:[~2023-09-06  7:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-26 21:59 Cache coherency bug: stale reads on /dev/sda1 Joshua Hudson
2023-08-27  1:03 ` Bagas Sanjaya
2023-08-27  1:25   ` Joshua Hudson
2023-08-27  2:06     ` Al Viro
2023-08-27  2:38       ` Joshua Hudson
2023-08-27  2:50         ` Bagas Sanjaya
2023-08-27  4:17         ` Al Viro
2023-08-27 14:39           ` Joshua Hudson
2023-08-27 16:30             ` Al Viro
2023-08-27 18:33               ` Joshua Hudson
2023-09-06  7:42                 ` Hannes Reinecke [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ee5affc-54b3-4b27-9311-4ed3bb73afc9@suse.de \
    --to=hare@suse.de \
    --cc=axboe@kernel.dk \
    --cc=bagasdotme@gmail.com \
    --cc=dlemoal@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=joshudson@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).