The second paragraph in Section 3.2.1 Basic Flat Model in "Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3" has the following sentence:
To implement a basic flat memory model with the IA-32 architecture, at least two segment descriptors must be created, one for referencing a code segment and one for referencing a data segment (see Figure 3-2). Both of these segments, however, are mapped to the entire linear address space: that is, both segment descriptors have the same base address value of 0 and the same segment limit of 4 GBytes.
Thus, I'm inclined to think that these two segments can overlap in memory, i.e., they may contain pages that belong to the code and the data segments. But this goes against the well behaved picture shown on Figure 3.2 (see below), where the two segments (CS and DS) don't intercept each other.
From this link I can see that my conjecture is correct, i.e., the code and the data segment can overlap.
Assume now that an instruction belonging to a page X in the code segment accesses data in the same page X. How does the system handle this case? It seems to me that the page X belonging to the code segment will have to be swapped to disk before the instruction is actually executed. Then, how is it going to be executed?